perf: add small root-node MRU cache for MARF storage connections#6944
perf: add small root-node MRU cache for MARF storage connections#6944cylewitruk-stacks wants to merge 8 commits intostacks-network:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a small (4-entry) root-node MRU cache to TrieStorageConnection (via TrieStorageTransientData) to reduce repeated root node disk reads in TrieCache::Noop mode.
Changes:
- Add an array-backed 4-entry MRU cache for committed-block root trie nodes (only active under
TrieCache::Noop). - Clear/clone root cache at connection fork/reopen and at unconfirmed invalidation/flush points to avoid stale reads.
- New tests and related helpers for confirmed/unconfirmed scenarios and MRU behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
stackslib/src/chainstate/stacks/index/storage.rs |
Adds root-node MRU cache field, wiring, and cache-hit/miss fast path for root reads in TrieCache::Noop. |
stackslib/src/chainstate/stacks/index/cache.rs |
Introduces MruCache (fixed-capacity array-backed MRU/LRU-eviction structure). |
stackslib/src/chainstate/stacks/index/test/storage.rs |
Adds tests for root cache correctness, eviction, unconfirmed skipping, and reopen cloning. |
stackslib/src/chainstate/stacks/index/test/mod.rs |
Adds shared helpers for temp MARF paths, minimal chains, and unconfirmed transactional inserts. |
stackslib/src/chainstate/stacks/index/test/marf.rs |
Adds regression test for repeated unconfirmed re-flushes preserving latest state. |
stackslib/src/chainstate/stacks/index/test/cache.rs |
Adds unit tests covering MruCache promotion/eviction/clear/capacity edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #6944 +/- ##
============================================
- Coverage 77.73% 56.52% -21.21%
============================================
Files 412 412
Lines 218667 219032 +365
Branches 338 338
============================================
- Hits 169981 123813 -46168
- Misses 48686 95219 +46533
... and 311 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Description
Adds a small 4-entry MRU cache for root trie nodes in
TrieStorageConnection(viaTrieStorageTransientData), minimizing disk lookups as allgets start at the root node.Excludes unconfirmed blocks since their blobs are updated in-place (a cached entry would go stale on re-flush).
The cache is cloned when forking read-only connections, and cleared at all unconfirmed trie invalidation points.
Applicable issues
Additional info (benefits, drawbacks, caveats)
TrieCache::Noop; other cache modes fall-through unchanged.Benchmark results
Using the benchmarks in #6932 --
noopcache mode shows a ~25-33% improvement ingettimings, ~17% reduction in number of allocations and ~25% reduction in bytes allocated (based on synthetic data).Checklist