Skip to content

perf: skip evaluating fully calculated window partitions - #24127

Open
neilconway wants to merge 1 commit into
apache:mainfrom
neilconway:neilc/perf-window-skip-caught-up-partitions
Open

perf: skip evaluating fully calculated window partitions#24127
neilconway wants to merge 1 commit into
apache:mainfrom
neilconway:neilc/perf-window-skip-caught-up-partitions

Conversation

@neilconway

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

In Linear mode, BoundedWindowAggStream's evaluation sweep visits every live partition for every window expression on every input batch. A partition can be safely skipped if it received no new rows and already row currently in the partition has its output fully computed. This avoids a bunch of redundant work: re-evaluating the window function arguments and ORDER BY columns against the retained batch, building an empty result array, and other bookkeeping. This is particularly expensive for workloads with many partitions where only a few of those partitions receive rows in a given batch, as in the "32k sparse" benchmark below.

Benchmarks:

  • linear / range / single / 100 dense: 42.3 ms -> 42.0 ms (~noise)
  • linear / range / single / 10000 dense: 158.7 ms -> 152.5 ms (-3.9%)
  • linear / range / single / 32768 sparse: 161.1 ms -> 108.0 ms (-33.0%)
  • linear / rows / single / 10000 dense: 132.0 ms -> 127.5 ms (-3.4%)
  • linear / range / multi / 10000 dense: 255.9 ms -> 236.4 ms (-7.6%)
  • sorted / range / single / 10000: 33.1 ms -> 33.7 ms (~noise)

What changes are included in this PR?

  • Skip evaluating window expressions for fully calculated partitions
  • Add test case
  • Add assert checking that per-window-agg and per-partition state is consistent

Are these changes tested?

Yes. Existing tests pass. Added a new test to verify that "evaluate partition -> skip partition -> evaluate partition" sequence results in resuming accumulator states appropriately. I also checked that if the is_end conjunct is removed from the skip condition, the new assert added above fires and catches the bug.

Are there any user-facing changes?

No.

In Linear mode, BoundedWindowAggStream's evaluation sweep visits every
live partition for every window expression on every input batch. A
partition that received no new rows and already has a result for every
buffered row cannot produce anything new can be safely skipped. This
avoids a bunch of redundant work: re-evaluating the window function
arguments and ORDER BY columns against the retained batch, building an
empty result array, and other bookkeeping. This is particularly
expensive for workloads with many partitions where only a few of those
partitions receive rows in a given batch, as in the "32k sparse"
benchmark below.

Benchmarks:

- linear / range / single / 100 dense:      42.3 ms ->  42.0 ms (~noise)
- linear / range / single / 10000 dense:   158.7 ms -> 152.5 ms (-3.9%)
- linear / range / single / 32768 sparse:  161.1 ms -> 108.0 ms (-33.0%)
- linear / rows  / single / 10000 dense:   132.0 ms -> 127.5 ms (-3.4%)
- linear / range / multi  / 10000 dense:   255.9 ms -> 236.4 ms (-7.6%)
- sorted / range / single / 10000:          33.1 ms ->  33.7 ms (~noise)
@github-actions github-actions Bot added logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates physical-plan Changes to the physical-plan crate labels Aug 5, 2026
@neilconway

Copy link
Copy Markdown
Contributor Author

cc @Dandandan ; similar in spirit to other recent optimization PRs to skip per-partition work when it is a no-op

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.10638% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.02%. Comparing base (3e3a92d) to head (3cbaae8).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...ysical-plan/src/windows/bounded_window_agg_exec.rs 82.27% 3 Missing and 11 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24127      +/-   ##
==========================================
+ Coverage   80.91%   81.02%   +0.10%     
==========================================
  Files        1103     1105       +2     
  Lines      377219   379798    +2579     
  Branches   377219   379798    +2579     
==========================================
+ Hits       305244   307743    +2499     
- Misses      53775    53823      +48     
- Partials    18200    18232      +32     

☔ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants