perf: skip evaluating fully calculated window partitions - #24127
Open
neilconway wants to merge 1 commit into
Open
perf: skip evaluating fully calculated window partitions#24127neilconway wants to merge 1 commit into
neilconway wants to merge 1 commit into
Conversation
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)
Contributor
Author
|
cc @Dandandan ; similar in spirit to other recent optimization PRs to skip per-partition work when it is a no-op |
Codecov Report❌ Patch coverage is
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. 🚀 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
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:
What changes are included in this PR?
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_endconjunct is removed from the skip condition, the new assert added above fires and catches the bug.Are there any user-facing changes?
No.