perf: share encoder/reservation across PartitionedTopKExec partition …#23096
Open
SubhamSinghal wants to merge 1 commit into
Open
perf: share encoder/reservation across PartitionedTopKExec partition …#23096SubhamSinghal wants to merge 1 commit into
SubhamSinghal wants to merge 1 commit into
Conversation
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?
Follow-up to #21479 (
PartitionedTopKExecforROW_NUMBER ... PARTITION BY ... LIMIT N) toward closing #6899.Rationale for this change
PartitionedTopKExectoday maintains aHashMap<OwnedRow, TopK>— one fullTopKper distinct partition key. EachTopKcarries its ownRowConverter,MemoryReservationregistered with the runtime pool,TopKMetrics, and scratchRowsbuffer. With high partition cardinality every partition seen for the first time pays:RowConverter::new(parsesSortFieldlist, allocates per-encoder state)MemoryConsumer::registerwith the pool (involves a global lock)TopKMetricssetupRows::empty_rowsallocationFor the h2o window-TopN sweep on a 10M-row CSV (
id3 % Npartition cardinality), this shows up as a regression at ≥10K partitions —PartitionedTopKExecis slower than the unpartitionedSortExecbaseline that it's meant to replace.What changes are included in this PR?
Adds a
PartitionedTopKsibling type totopk/mod.rsthat holds the shared encoder/reservation/metrics state once at the operator level and aHashMap<OwnedRow, TopKHeap>of cheap per-partition heap state.PartitionedTopKExecswitches fromHashMap<OwnedRow, TopK>to onePartitionedTopK.Bench results
Today's default (main, flag-off) vs this PR (flag-on)
h2o
id3 % Nsweep, 10M-row CSV, 3 iterations per query, release build,enable_window_topn=trueon both sides:main10K is the inflection point: on
mainit's a regression vs the sort baseline (640 ms vs 234 ms); after this PR it's a win (137 ms vs 234 ms — 1.7× faster than sort). 100K nearly catches up to the sort baseline (320 ms vs 238 ms).enable_window_topndefault staysfalseper the #21479 discussion — 100K+ remains slower than sort on average, so this PR doesn't motivate flipping the default. It's the prerequisite for further optimizations that would attack the residual 100K+ cliff.Are these changes tested?
Yes
Are there any user-facing changes?
No public API changes.