Sort: improve some of the performances#11412
Open
sylvestre wants to merge 3 commits intouutils:mainfrom
Open
Conversation
Expose ICU4X's write_sort_key_utf8_to via a public helper that appends a collation sort key to a caller-supplied buffer. This enables computing sort keys once per line (O(n)) and then comparing cheap byte arrays during sorting, instead of calling compare_utf8 on every comparison.
Add collation_key_buffer (arena) and collation_key_ends (offsets) to LineData and RecycledChunk, with a collation_key() accessor. All sort keys for a chunk are stored in a single Vec<u8> to avoid millions of small heap allocations.
Add a fast_locale_collation path that pre-computes ICU sort keys during line parsing (O(n)), then uses cheap byte-array comparison during sorting (O(n log n)). This replaces per-comparison ICU compare_utf8 calls for the common case of plain `sort` with a UTF-8 locale. With 1M lines and LC_ALL=en_US.UTF-8, this is ~2.6x faster than GNU sort (314ms vs 822ms).
Merging this PR will degrade performance by 45.43%
Performance Changes
Comparing Footnotes
|
Contributor
Author
|
i am fine trading memory vs speed :) |
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.
Closes: #11258