Feike/malloc performance improvements#852
Closed
feikesteenbergen wants to merge 23 commits intomainfrom
Closed
Conversation
replaced https://docs.timescale.com/latest/using-timescaledb/continuous-aggregates with https://docs.timescale.com/use-timescale/latest/continuous-aggregates/ Signed-off-by: Anthony Shaw <109225504+xyztony@users.noreply.github.com>
This was deprecated: rust-lang/cargo#13349
This is needed for allowing certain sort operations to take place. It is also true that a HashKey has a total Ordering, so there wasn't much to change anyways.
Profiling showed us that we spend a lot of time in the compact function (60%+ for the current test suite). We therefore want to reduce: - malloc calls - cpu usage in general We do so by introducing a Vec that is only used during the compaction itself, the actual HashMap will be reused every time. The Vec itself will also stick around once it has been allocated. We also instead of walking through the HashMap by following the linked list, drain the HashMap, which should reduce the amount of comparisons required, and therefore reduce CPU
This reduces the amount of memory allocations drastically
feikesteenbergen
commented
Apr 4, 2025
crates/udd-sketch/src/lib.rs
Outdated
|
|
||
| while self.buckets.len() > self.max_buckets as usize { | ||
| self.compact_buckets(); | ||
| self.compact_buckets(&mut Vec::new()); |
Member
Author
There was a problem hiding this comment.
Could reuse a vec here as well
This implementation isn't optimal yet, however, it is there to ensure correctness
Member
Author
|
Closing in favor of the simpler #853 |
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.
Attempt to reduce malloc calls and improve performance
TLDR: reduces malloc calls by 70% without requiring additional memory.
Why? We used to reallocate the
HashMapbacking the sketches every compaction.Now, we use a
Vecto temporarily store the values while compacting, allowingus to reuse the
HashMapVeccan quickly be deallocated again if neededThis is a work in progress, and has some rough edges
Baseline
After having added some tests, these are the numbers:
Switching to a permanent Vec
Works, is faster, less
malloc, yet high memory usage (during the tests)Switching to a temp Vec
Switching to a reusable Vec
random_stress: (*10): 8.07 seconds
Call Tree: (fuzzing_test)
memory