feat: add lazy loading for large BTreeMap keys#312
Merged
Conversation
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces lazy key loading for BTreeMap nodes by eagerly loading keys when their size is small and deferring loading for larger keys. Key changes include updating node implementations in both V1 and V2, refactoring public APIs to pass memory context, and introducing a LazyKey type to encapsulate lazy key behavior.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/btreemap/node/v2.rs | Eagerly loads small keys using a threshold while deferring large ones. |
| src/btreemap/node/v1.rs | Updates key/value loading to use lazy references and adjusts offsets. |
| src/btreemap/node.rs | Refactors key handling with LazyKey and propagates memory parameters. |
| src/btreemap/iter.rs | Updates iterator methods to include memory context in key retrieval. |
| src/btreemap.rs | Propagates memory context across search and insertion operations. |
Comments suppressed due to low confidence (1)
src/btreemap/node/v2.rs:170
- When eagerly loading small keys, the same mutable buffer 'buf' is reused across iterations. If K::from_bytes does not clone the key bytes, this may lead to data corruption in subsequent iterations. Consider cloning the loaded bytes or allocating a new buffer for each key.
read_to_vec(&reader, Address::from(offset.get()), &mut buf, key_size as usize);
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.
This PR enables lazy key loading in
BTreeMapfor large keys.Keys larger than a fixed threshold are now loaded lazily, reducing unnecessary memory reads. Smaller keys are still loaded eagerly for performance. After benchmarking various thresholds (4, 8, 16, 32, 64 bytes), 16 bytes was found to offer the best balance between performance and overhead.
Detailed benchmark results are available in this CSV report