Skip to content

perf: skip re-slicing window partition batches with nothing to prune - #24047

Merged
neilconway merged 1 commit into
apache:mainfrom
neilconway:neilc/perf-window-skip-noop-prunes
Aug 3, 2026
Merged

perf: skip re-slicing window partition batches with nothing to prune#24047
neilconway merged 1 commit into
apache:mainfrom
neilconway:neilc/perf-window-skip-noop-prunes

Conversation

@neilconway

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale 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:

- 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%)

What changes are included in this PR?

See above.

Are these changes tested?

Covered by existing tests.

Are there any user-facing changes?

No.

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%)
@github-actions github-actions Bot added the physical-plan Changes to the physical-plan crate label Aug 1, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.85%. Comparing base (b902256) to head (0ebd494).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Dandandan Dandandan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@neilconway
neilconway added this pull request to the merge queue Aug 3, 2026
Merged via the queue into apache:main with commit 47ca490 Aug 3, 2026
40 checks passed
@neilconway
neilconway deleted the neilc/perf-window-skip-noop-prunes branch August 3, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants