fix(rust): aggregate size() audit — count all per-group heap in ItemCrs, union/intersection, and envelope accumulators - #1227
Merged
Conversation
…n size() The previous size() only counted coordinates, and only when the held geometry was the MultiPolygon variant: any other variant contributed zero, and container overhead (the polygon buffer, per-ring LineString headers, interior-ring buffers) was never counted. Replace the hand-rolled walk with a variant-exhaustive geometry_heap_size() shared by both accumulators. The MultiPolygon-only invariant these accumulators maintain still holds; the total walk makes size() robust to future changes rather than silently reporting zero.
…ccumulator2D::size()
james-willis
force-pushed
the
jw/agg-size-audit
branch
from
September 2, 2026 23:50
597defc to
a327b09
Compare
james-willis
marked this pull request as ready for review
September 3, 2026 22:46
paleolimbot
approved these changes
Sep 4, 2026
paleolimbot
left a comment
Member
There was a problem hiding this comment.
Thank you!
There is also a place in sedona-spatial-join where I believe we approximate or ignore the memory used by geo geometries that might be worth updating here. That may be more performance sensitive because we're estimating the usage of a Vec of geometries rather than just one.
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.
Follow-up to #1225: after fixing
ST_Collect_Agg's memory accounting, we audited every otherAccumulator/GroupsAccumulatorsize()implementation in the repo (enumerated via the trait-requiredfn size(&self) -> usize, cross-checked with a repo-wide sweep for per-group set/collection state). Three more accounting gaps turned up, each small; this PR fixes all three as separate commits. No behavior changes — only what gets reported to the memory pool.1.
ItemCrsAccumulator(sedona-expr)size()returnedinner.size() + size_of::<ItemCrsAccumulator>(), omitting the per-groupcrs: Option<String>heap. Since this wrapper multiplies across every aggregate over item-CRS arguments, a high-cardinalityGROUP BYleaked one uncounted String allocation per group. Fix adds the string's capacity.2.
ST_Union_Agg/ST_Intersection_Agg(sedona-geo)These accumulators hold a growing
MultiPolygon(the running union/intersection), yetsize()counted only the raw coordinate bytes inside it — and by ring.len(), not.capacity(). Every container that holds those coordinates together went uncounted: theMultiPolygon's ownVec<Polygon>buffer, eachPolygon's interior-ringsVec<LineString>buffer, the per-ringLineStringheaders, and any capacity slack in the coordinate vectors.For the workload these accumulators exist to serve — dissolving many small polygons into one accumulating
MultiPolygon— theVec<Polygon>buffer alone scales with the polygon count (eachgeo::Polygonis a ~48-byte struct), so on small features the uncounted structural overhead is comparable to the coordinate bytes that were counted: roughly a 40–50% under-report that grows as the union does.The fix replaces the hand-rolled walk with a shared
geometry_heap_size()(new crate-privategeometry_memmodule, with tests) that charges for every owned buffer — coordinates by capacity, the polygon and ring vectors, and recursion through nested geometries. As a side benefit the new walk is variant-exhaustive, so it can no longer silently report zero if the held geometry is ever something other than aMultiPolygon; that path isn't reachable today (the accumulators maintain a MultiPolygon-or-None invariant), but the walk is robust either way.3.
BoundsGroupsAccumulator2D(sedona-functions)The groups accumulator summed per-bounder
mem_used()over the live bounders, missing thebounders: Vec<T>doubling slack (capacity beyond len). Smallest of the three — added the slack term.Not in scope
ST_ConvexHull_AggandST_Analyze_Aggwere audited and are already honest (capacity-based counting and the u32 bitset respectively). The largerST_Collect_Aggfollow-ups discussed in #1225 (nativeGroupsAccumulator, DataFusion-side adapter accounting) remain separate work.