Repository navigation
Sort message identifiers once when chunking - #206
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Chunking messages currently sorts the entire search result before fetching each page. With 35,798 messages and a chunk size of 10, that sorts the same UID list 3,580 times.
This moves client-side ordering into
sortMessages(), which runs once before the chunk loop and before pagination for normal retrieval. It preserves ascending and descending fetch order and the existing handling of server-side sorting.search()continues to return matching UIDs directly, so counting and bulk operations avoid unnecessary sorting.The following benchmarks compare this change against v1.25.10 on PHP 8.4.27 with CLI OPcache and JIT disabled. They exercise
chunk()using synthetic SEARCH responses containing ascending UIDs with gaps, then retrieve messages in the default newest-first order.Results are averages across six alternating runs per version, except the 35,798-UID workload with chunks of 10, which used two runs per version. Measurements include parsing the in-memory SEARCH response, pagination, and message object construction. Network latency and fetching message bodies or metadata are excluded. Every run verified the returned UIDs, their order, and the chunk count.
All 1,038 unit tests pass.
Refs #200.