-
Notifications
You must be signed in to change notification settings - Fork 189
fix: remove excess vec capacity in caches #5935
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -203,14 +203,17 @@ impl EnabledTipsetDataCache { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| impl TipsetReceiptEventCacheHandler for EnabledTipsetDataCache { | ||||||||||||||||||||||||||
| fn insert_receipt(&self, key: &TipsetKey, receipts: Vec<Receipt>) { | ||||||||||||||||||||||||||
| fn insert_receipt(&self, key: &TipsetKey, mut receipts: Vec<Receipt>) { | ||||||||||||||||||||||||||
| if !receipts.is_empty() { | ||||||||||||||||||||||||||
| receipts.shrink_to_fit(); | ||||||||||||||||||||||||||
| self.receipt_cache.insert(key.clone(), receipts); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| fn insert_events(&self, key: &TipsetKey, events_data: StateEvents) { | ||||||||||||||||||||||||||
| fn insert_events(&self, key: &TipsetKey, mut events_data: StateEvents) { | ||||||||||||||||||||||||||
| if !events_data.events.is_empty() { | ||||||||||||||||||||||||||
| events_data.events.shrink_to_fit(); | ||||||||||||||||||||||||||
| events_data.roots.shrink_to_fit(); | ||||||||||||||||||||||||||
| self.events_cache.insert(key.clone(), events_data); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+213
to
219
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainSame here: cache empty event sets to avoid unnecessary re-computation As with receipts, events can legitimately be empty. Skipping insertion changes cache semantics and may increase CPU churn. - fn insert_events(&self, key: &TipsetKey, mut events_data: StateEvents) {
- if !events_data.events.is_empty() {
- events_data.events.shrink_to_fit();
- events_data.roots.shrink_to_fit();
- self.events_cache.insert(key.clone(), events_data);
- }
- }
+ fn insert_events(&self, key: &TipsetKey, mut events_data: StateEvents) {
+ events_data.events.shrink_to_fit();
+ events_data.roots.shrink_to_fit();
+ self.events_cache.insert(key.clone(), events_data);
+ }You can also scan for call sites: 🏁 Script executed: #!/bin/bash
rg -n "insert_events\(|get_events_or_else\(" -A 3 -B 3Length of output: 3584 🏁 Script executed: #!/bin/bash
rg -n "events_cache" -A5 -B5 src/state_manager/cache.rsLength of output: 1649 🏁 Script executed: #!/bin/bash
rg -n "fn insert_receipt" -A5 -B5 src/state_manager/cache.rsLength of output: 1390 🏁 Script executed: #!/bin/bash
rg -n "struct TipsetStateCache" -A5 -B5 .Length of output: 1434 Always cache empty Skipping insertion when Points of attention:
Suggested diff: - fn insert_events(&self, key: &TipsetKey, mut events_data: StateEvents) {
- if !events_data.events.is_empty() {
- events_data.events.shrink_to_fit();
- events_data.roots.shrink_to_fit();
- self.events_cache.insert(key.clone(), events_data);
- }
- }
+ fn insert_events(&self, key: &TipsetKey, mut events_data: StateEvents) {
+ events_data.events.shrink_to_fit();
+ events_data.roots.shrink_to_fit();
+ self.events_cache.insert(key.clone(), events_data);
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe empty vec indicates value computation is skipped, thus should not be cached. cc @aatifsyed to confirm
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think I have enough context to confirm or deny! Is this a Rust question, a protocol question, or a library question? :))
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @aatifsyed thanks for your reply! I actually meant to tag @akaladarshi on this sorry about it and have a great day! |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
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.
💡 Verification agent
🧩 Analysis chain
Don’t skip caching empty receipts; it causes repeated recomputation and changes semantics
Gating insertion on non-empty vectors changes behavior: callers that legitimately produce empty receipts will no longer be cached and may recompute on subsequent lookups. Empty results are still results and should be cached (negative caching).
Apply this change to always cache, while still shrinking:
To check current usage patterns and potential reliance on empty caching, run:
🏁 Script executed:
Length of output: 4422
Always cache empty receipts for proper negative caching
Currently both the handler and its caller short-circuit empty vectors, so empty receipt results are never stored—causing repeated recomputation. We need to:
• In src/state_manager/cache.rs, remove the
if !receipts.is_empty()guard ininsert_receiptso it always callsinsert(...)aftershrink_to_fit().• In src/state_manager/mod.rs, remove the surrounding
if !receipts.is_empty()check before callinginsert_receiptso empty vectors get cached.Proposed diffs:
This ensures that even an empty
Vec<Receipt>is cached once and won’t trigger redundant recomputations inget_receipt_or_else.🤖 Prompt for AI Agents
Uh oh!
There was an error while loading. Please reload this page.
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.
I believe empty vec indicates value computation is skipped, thus should not be cached. cc @akaladarshi to confirm
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.