Account for hybrid cache entry overhead - #104
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🟡 Changes recommended
The new weigher/test currently uses String::len() instead of capacity(), which can undercount retained heap memory and misalign eviction/capacity accounting.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates hybrid cache capacity accounting so entry weights reflect not only article payload bytes, but also key storage, in-memory metadata, and serialized framing overhead—keeping eviction behavior better aligned with actual retained footprint.
Changes:
- Introduce a shared
hybrid_entry_weightused by both production and memory-only hybrid cache builders. - Add
DiskCachedArticle::encoded_len()to measure serialized value size including metadata and payload framing. - Add a focused unit test to validate the new weight calculation behavior.
File summaries
| File | Description |
|---|---|
src/cache/hybrid.rs |
Switches foyer weighter from payload-only to a composite entry weight and adds a unit test for the new accounting. |
src/cache/hybrid_codec.rs |
Adds encoded_len() and a fixed-size constant to represent serialized entry overhead for weight calculations. |
Review details
Suppressed comments (1)
src/cache/hybrid.rs:720
- This test hard-codes
short_key.len()in the expected weight. If the weighter is meant to track retained memory, it should usecapacity()(matching the production code) so the assertion remains correct for strings with reserved capacity.
size_of::<String>()
+ short_key.len()
+ size_of::<DiskCachedArticle>()
+ missing.encoded_len()
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
c15f877 to
b5db963
Compare
d6fbd37 to
4f3244a
Compare
Summary
Branch-added tests