Repository navigation
perf: buffer HLL input values in the arena, move CPC states to the arena - #29
Merged
Merged
Conversation
DuckDB creates one aggregate state per input row when grouping reduces little, and each HLL state built a whole union in the arena (about three allocations): datasketch_hll(12, v) over 20M rows in 2M groups ran out of memory at a 1 GB limit. CPC states still lived on the heap with a destructor, so DuckDB neither counted nor spilled them (3.6 GB peak under a 1 GB limit). HLL create states now keep their first 7 distinct values in the arena (fixed-width values bytewise, VARCHAR/BLOB bytes copied) and feed them to a union only when more arrive, at finalize, or when merging a state that has a union. Up to 7 coupons stay in a union's LIST mode, which merges by feeding coupons in arrival order, so appending buffered values gives the same union as merging unions. Buffered states serialize through a heap union and export as raw values. CPC create and union aggregates are arena states too. CPC states buffer 16 values; two non-empty partial states still merge through a (heap) union whose result is assigned into the arena sketch, so results match the heap implementation. A constant input is added once (a sketch absorbs a repeated value once). 20M rows, 2M groups, 1 GB limit, 8 threads: HLL: out of memory -> 6.9 s, 0.82 GB peak RSS CPC: 10.4 s, 3.6 GB peak RSS -> 7.7 s, 0.77 GB peak RSS Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Builds on #27.
datasketch_hll(12, v)datasketch_cpc(12, v)HLL
CPC
datasketch_cpcanddatasketch_cpc_unionnow use arena states, and create states buffer 16 values.Also in this PR
arena=Truefor counting sketches.Tests
New
test/sql/datasketch_spill_counting.test, under 128 MB with 4 threads:EXPORT_STATEwithfinalizeandcombineAll tests pass.
🤖 Generated with Claude Code