feat(arrow-row): add MSD radix sort kernel for row-encoded keys#9683
Open
mbutrovich wants to merge 8 commits intoapache:mainfrom
Open
feat(arrow-row): add MSD radix sort kernel for row-encoded keys#9683mbutrovich wants to merge 8 commits intoapache:mainfrom
mbutrovich wants to merge 8 commits intoapache:mainfrom
Conversation
Contributor
Author
|
Full
|
Dandandan
reviewed
Apr 9, 2026
Dandandan
reviewed
Apr 9, 2026
Dandandan
reviewed
Apr 9, 2026
Dandandan
reviewed
Apr 9, 2026
Contributor
Author
|
Thanks for the feedback @Dandandan! I tried the 4 optimizations you suggested, and here are the results:
Claude's attempt at interpreting the results:
Do you want the commit anyway just to iterate off of? |
Contributor
Author
|
Byte Buffer is the current commit:
Here it is compared to the other sorts:
|
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.
Which issue does this PR close?
N/A.
Rationale for this change
The existing
lexsort_to_indicesuses comparison sort on columnar arrays, which is O(n log n × comparison_cost) where comparison cost scales with the number of columns. The Arrow row format (RowConverter) produces memcmp-comparable byte sequences, making it a natural fit for radix sort — O(n × key_width) — which can overcome the encoding overhead by eliminating per-comparison column traversal.Inspired by DuckDB's sorting redesign, which uses MSD radix sort on normalized key prefixes with a comparison sort fallback, this PR adds an
radix_sort_to_indiceskernel that operates directly on row-encoded keys. Like DuckDB, we limit radix depth to 8 bytes before falling back to comparison sort, balancing radix efficiency against diminishing returns on deep recursion.What changes are included in this PR?
arrow-row/src/radix.rs(new): MSD radix sort onRowswith:arrow-row/src/lib.rs: Exposespub mod radixarrow/benches/lexsort.rs: Addslexsort_radixbenchmark variant alongside existinglexsort_to_indicesandlexsort_rows, and removes a duplicate benchmark caseBenchmark results
All three variants include the full pipeline (encoding + sort) so the comparison against
lexsort_to_indices(which doesn't encode) is apples-to-apples. Here are a subset of results fromcargo bench --bench lexsort. I'll post the full table in a follow-up comment.Radix sort is the fastest in the majority of cases. The main exception is pure low-cardinality dictionary columns where
lexsort_to_indicesavoids encoding overhead entirely. The module documentation provides guidance on when to use each approach.Are these changes tested?
17 tests including:
RowsAre there any user-facing changes?
New public API:
arrow_row::radix::radix_sort_to_indices(&Rows) -> Vec<u32>.