-
Couldn't load subscription status.
- Fork 34
feat: add lazy loading for large BTreeMap keys #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm!
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