perf(core): strength reduce hash partition modulo - #2363
Merged
Dandandan merged 1 commit intoAug 25, 2026
Conversation
phillipleblanc
approved these changes
Aug 25, 2026
Dandandan
approved these changes
Aug 25, 2026
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?
Closes #.
Rationale for this change
This is a vibe-port of the same change in DataFusion's
BatchPartitioner(apache/datafusion#21900), where it measured up to 1.16x on TPC-H sf10. The type
is private to
datafusion-physical-plan, so it cannot be reused directly.Also verified by eye to ensure it makes sense.
@Dandandan cc
What changes are included in this PR?
StrengthReducedU64is built once per task and threaded intocompute_partition_indices, replacing the per-row%. Partition assignment isunchanged.
try_newnow rejects a zero output partition count, which previouslywould have divided by zero.
AI Benchmark:
8192 rows/batch, 200 batches, hash on an int64 key, release, best of 15 —
timing all of
compute_partition_indices(hash + index build):Scope of the speedup
The 1.8–2.2x above is for
compute_partition_indicesin isolation. That functionis one phase of writing a shuffle, so the effect on the write step as a whole is
smaller. Phase split, 50 batches x 8192 lineitem-shaped rows, LZ4, best of 8:
Only the first row is touched by this PR; the rest is untouched. Applying the
measured phase speedup to that share:
So roughly 5-7% off the shuffle write step, and less than that on query wall
clock, since the write step is itself only part of a query. For comparison,
apache/datafusion#21900 made the same change where it is a larger share of the
work and landed at up to 1.16x on TPC-H sf10.
Are these changes tested?
Ported the tests over:
strength_reduced_u64_remainder_matches_modulochecks the reduced formagainst
%for 25 divisors × 21 boundary values plus a 10,000-valuepseudo-random sweep per divisor;
strength_reduced_u64_partition_indices_matches_modulochecks the productionentry point against a plain
%loop on both paths. The existingcompute_partition_indices_matches_batch_partitionerdrift test againstDataFusion's
BatchPartitionerstill passes unchanged.Are there any user-facing changes?
no