perf: skip re-slicing window partition batches with nothing to prune - #24047
Merged
neilconway merged 1 commit intoAug 3, 2026
Merged
Conversation
After each emission, BoundedWindowAggStream prunes the rows of each partition's buffered batch that no longer contribute to any window frame. The prune loop re-sliced every live partition's RecordBatch even when there was nothing to prune, allocating fresh array metadata for an identical batch and then dropping the replaced one. Profiling the many-partitions benchmark showed prune_state at ~39% of the sparse case, where nearly all live partitions are quiet and almost every slice is a no-op, and ~21% of the dense case, where most slices prune real rows and only the partitions missed by a batch hit the no-op path. One simple improvement is to leave a partition's buffered batch untouched when the prune count is zero. This avoids the array metadata allocation churn mentioned above. Benchmarks: - linear, range, single, 100 part, dense: 44.1 ms -> 43.8 ms (~noise) - linear, range, single, 10000 part dense: 171.1 ms -> 164.8 ms (-3.6%) - linear, range, single, 32768 part sparse: 209.4 ms -> 166.1 ms (-20.6%) - linear, rows, single, 10000 part dense: 141.5 ms -> 136.4 ms (-3.7%) - linear, range, multi, 10000 part dense: 268.0 ms -> 261.0 ms (-2.6%) - sorted, range, single, 10000 part: 34.0 ms -> 34.3 ms (+0.9%)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #24047 +/- ##
==========================================
- Coverage 80.86% 80.85% -0.01%
==========================================
Files 1101 1101
Lines 375446 375449 +3
Branches 375446 375449 +3
==========================================
- Hits 303598 303582 -16
- Misses 53758 53774 +16
- Partials 18090 18093 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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?
BoundedWindowAggExecinLinearmode is slow for many-partitions #23982Rationale for this change
After each emission, BoundedWindowAggStream prunes the rows of each partition's buffered batch that no longer contribute to any window frame. The prune loop re-sliced every live partition's RecordBatch even when there was nothing to prune, allocating fresh array metadata for an identical batch and then dropping the replaced one.
Profiling the many-partitions benchmark showed prune_state at ~39% of the sparse case, where nearly all live partitions are quiet and almost every slice is a no-op, and ~21% of the dense case, where most slices prune real rows and only the partitions missed by a batch hit the no-op path.
One simple improvement is to leave a partition's buffered batch untouched when the prune count is zero. This avoids the array metadata allocation churn mentioned above.
Benchmarks:
What changes are included in this PR?
See above.
Are these changes tested?
Covered by existing tests.
Are there any user-facing changes?
No.