Repository navigation
perf: tdigest grows its buffers as they fill - #561
Open
rustyconover wants to merge 1 commit into
Open
rustyconover wants to merge 1 commit into
rustyconover wants to merge 1 commit into
Conversation
The constructor reserved room for 2k + fudge centroids and four times as many buffered values (about 10 KB for k = 100 with doubles), also when deserializing. Code that holds many small t-digests paid for all of it. Grow the buffer geometrically up to its limit on update, and the centroids before a compress or merge needs them. Results are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
tdigest's constructor reserves room for2k + fudgecentroids andBUFFER_MULTIPLIERtimes as many buffered values. Fork = 100withdoublethat's about 10 KB per digest before anything is added, and it happens again on everydeserialize().This is the same kind of change as #558 for
kll_sketch. Instead of reserving everything up front:update()grows the buffer geometrically, starting at 8 values and doubling up to its existing limit.compress()andmerge()grow the centroids before they need them, also up to the existing limit.Results and the serialized format are unchanged.
Test
Added
tdigest custom allocator: buffers grow as they filltotdigest_custom_allocator_test.cpp, usingtest_allocator:REQUIRE( test_allocator_total_bytes == 0 ).std::allocatorwithout the change.All 17 test suites pass under CTest (GCC 14, aarch64).
We found this in the DuckDB DataSketches extension. For GROUP BY queries with many groups, DuckDB creates a state for each input row and merges them later, so the up-front reservation multiplied by millions of states. DuckDB made the same change to its own t-digest.
🤖 Generated with Claude Code