Repository navigation
Reduce Keeper memory usage with compact children set - #99860
Merged
Merged
Conversation
Introduce `CompactChildrenSet`, a memory-optimized container for Keeper node children that stores 0-1 children inline (no heap allocation) and switches to a flat hash set only when there are 2+ children. This reduces `KeeperMemNode` size from 144 to 128 bytes. Most Keeper nodes have 0 or 1 children, so this optimization avoids heap allocation overhead for the common case, significantly reducing memory consumption in large Keeper deployments. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
antonio2368
force-pushed
the
keeper-children-compact
branch
from
March 18, 2026 10:41
98ce87f to
39702a0
Compare
Contributor
Member
Author
|
On some snapshots I checked I noticed that 66% of nodes were leaf nodes and 33% had only 1 child. |
- `performance-unnecessary-copy-initialization`: suppress with NOLINT for intentional copy-constructor tests - `readability-isolate-declaration`: split multi-variable bool declaration https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=99860&sha=39702a03f5987cb452c10d9f16f9ff30bc31dfbc&name_0=PR&name_1=Build%20%28arm_tidy%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Algunenano
reviewed
Mar 18, 2026
| ConstIterator end() const; | ||
|
|
||
| /// Returns the number of bytes allocated on the heap for this container. | ||
| /// Zero for empty/single states (inline storage), approximate for set mode. |
Member
There was a problem hiding this comment.
This comment is a bit confusing. I think it'd be better to only mention inline storage and not empty/single states, since you might call reserve and technically you expect the storage to be empty (nothing was inserted) but it's already using set mode and heap memory. I find empty() vs isEmpty() confusing too, but I don't know a better name for isEmpty() that isn't too verbose. Maybe you do
- Use a union for `sv` and `set_it` in `ConstIterator` since they are never active simultaneously, reducing iterator size from 40 to 24 bytes - Add `chassert` in the set-to-single demotion path to verify the remaining child name is non-empty - Fix `heapSizeInBytes` to use `capacity` instead of `size` Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Algunenano
approved these changes
Mar 18, 2026
`LOGICAL_ERROR` exceptions call `abortOnFailedAssertion` in debug and sanitizer builds, so `EXPECT_THROW` can never catch them — the process aborts first. Wrap the test body in `#ifndef DEBUG_OR_SANITIZER_BUILD`, matching the established pattern in `gtest_memory_resize.cpp`. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=99860&sha=latest&name_0=PR Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Contributor
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 98.59% (560/568, 1 noise lines excluded) |
1 task
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.
Reduce memory consumption of Keeper by replacing
absl::flat_hash_setwithCompactChildrenSetfor storing node children. The new container stores 0–1 children inline without heap allocation, which covers the majority of Keeper nodes. This reducesKeeperMemNodesize from 144 to 128 bytes.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reduce memory consumption of Keeper by replacing
absl::flat_hash_setwithCompactChildrenSetfor storing node children. The new container stores 0–1 children inline without heap allocation, which covers the majority of Keeper nodes. This reducesKeeperMemNodesize from 144 to 128 bytes.Documentation entry for user-facing changes
Version info
26.3.1.846