chore: adjust size accounting for min_max - #23899
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #23899 +/- ##
=======================================
Coverage 80.65% 80.65%
=======================================
Files 1092 1092
Lines 371106 371188 +82
Branches 371106 371188 +82
=======================================
+ Hits 299323 299396 +73
+ Misses 53937 53933 -4
- Partials 17846 17859 +13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Jefffrey
approved these changes
Jul 26, 2026
Contributor
Author
|
Thanks @Jefffrey for the review! |
kosiew
pushed a commit
to kosiew/datafusion
that referenced
this pull request
Aug 12, 2026
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes apache#123` indicates that this PR will close issue apache#123. --> - Part of apache#23393 . ## Rationale for this change `SlidingMinAccumulator::size` and `SlidingMaxAccumulator::size` only reported the stack size of their `ScalarValue` field plus its heap payload, ignoring the memory held by the underlying `MovingMin` / `MovingMax` sliding-window buffers. For windowed `MIN`/`MAX` over string or list data, the two per-element stacks can hold megabytes of `ScalarValue` payload that the memory pool was never told about, understating accumulator memory usage. ## What changes are included in this PR? - Add a private `heap_size(elem_heap)` method to `MovingMin<T>` and `MovingMax<T>` that reports the two stack buffers' capacity in bytes plus each stored element's heap payload. - Factor the shared implementation into a `moving_stacks_heap_size` free helper so the two types stay in sync. - Include the buffer bytes in `SlidingMinAccumulator::size` and `SlidingMaxAccumulator::size` via the new method. ## Are these changes tested? Yes. Two new unit tests in `datafusion/functions-aggregate/src/min_max.rs`: - `moving_min_max_heap_size_i32` — fixed-width `T`, verifies buffer-only accounting with and without pushed elements. - `moving_min_max_heap_size_counts_elems` — `T = String`, verifies each of the two slots in a `(T, T)` pair contributes independently to the heap payload (mirroring the two independent `Clone`s made by `push`).
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?
Part of feat: analyze memory usage for
sizefunctions #23393 .Rationale for this change
SlidingMinAccumulator::sizeandSlidingMaxAccumulator::sizeonly reportedthe stack size of their
ScalarValuefield plus its heap payload, ignoring thememory held by the underlying
MovingMin/MovingMaxsliding-window buffers.For windowed
MIN/MAXover string or list data, the two per-element stackscan hold megabytes of
ScalarValuepayload that the memory pool was nevertold about, understating accumulator memory usage.
What changes are included in this PR?
heap_size(elem_heap)method toMovingMin<T>andMovingMax<T>that reports the two stack buffers' capacity in bytes plus each stored
element's heap payload.
moving_stacks_heap_sizefree helperso the two types stay in sync.
SlidingMinAccumulator::sizeandSlidingMaxAccumulator::sizevia the new method.Are these changes tested?
Yes. Two new unit tests in
datafusion/functions-aggregate/src/min_max.rs:moving_min_max_heap_size_i32— fixed-widthT, verifies buffer-onlyaccounting with and without pushed elements.
moving_min_max_heap_size_counts_elems—T = String, verifies each of thetwo slots in a
(T, T)pair contributes independently to the heap payload(mirroring the two independent
Clones made bypush).