Skip to content

[mpt] count hits, misses and evictions in the trie node cache - #2504

Open
maxkozlovsky wants to merge 1 commit into
max/cache-statsfrom
max/node-cache-stats
Open

[mpt] count hits, misses and evictions in the trie node cache#2504
maxkozlovsky wants to merge 1 commit into
max/cache-statsfrom
max/node-cache-stats

Conversation

@maxkozlovsky

Copy link
Copy Markdown
Contributor

Wire CacheStats into static_lru_cache and NodeCache. a follow-up exports them over the triedb FFI.

Two related fixes in NodeCache while making its occupancy observable. insert() charged the full size of the incoming node before evicting, so an overwrite -- which replaces an entry already accounted for -- could evict entries to make room it did not need; it now applies the net change. And NodeCache no longer re-exports Base::clear, which left used_bytes_ stale while size() read zero.

Copilot AI lite review requested due to automatic review settings August 20, 2026 22:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds cache hit/miss/eviction metrics and byte-occupancy tracking to the LRU and trie node caches.

Changes:

  • Integrates CacheStats and non-mutating contains() checks.
  • Corrects NodeCache overwrite accounting.
  • Adds tests for metrics, occupancy, and cache behavior.

Review finding: clear() leaves active_list_ populated, causing stale values and false eviction statistics on subsequent inserts. This is a moderate P2 issue with 2 votes.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Summary
category/mpt/test/node_lru_cache_test.cpp Tests NodeCache metrics and accounting.
category/mpt/node_cache.hpp Tracks cache statistics and used bytes.
category/mpt/find_notify_fiber.cpp Uses non-mutating cache existence checks.
category/core/lru/static_lru_test.cpp Tests LRU statistics and behavior.
category/core/lru/static_lru_cache.hpp Adds statistics and contains(); clear() requires correction.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +139 to +142
CacheStatsSnapshot stats() const noexcept
{
return stats_.snapshot();
}

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the wiring of CacheStats into static_lru_cache and NodeCache, the new contains() predicate, and the two ancillary fixes called out in the PR description (insert() net-change accounting, dropping the leaky using Base::clear).

Walked through all insert() cases (fresh into a free slot, overwrite of an existing key, LRU-tail reuse when the map is full, and a single node oversized vs max_bytes) — bytes accounting and eviction counting are correct on every path, with no double-counted eviction across Base::insert and evict_until_under_limit. All existing callers of NodeCache::insert ignore the returned iterator, so narrowing the return to void is safe. All remaining call sites of find() on NodeCache still use the accessor (not existence checks), so no other spot needs the contains() swap. The stats atomics are relaxed-order, which is right for stats and correctly leaves static_lru_cache non-copyable/non-movable — no code in the tree copies or moves it.

Verdict: CORRECT

🤖 Generated with Claude Code

Wire CacheStats into static_lru_cache and NodeCache. a follow-up exports
them over the triedb FFI.

Two related fixes in NodeCache while making its occupancy observable. insert()
charged the full size of the incoming node before evicting, so an overwrite --
which replaces an entry already accounted for -- could evict entries to make
room it did not need; it now applies the net change. And NodeCache no longer
re-exports Base::clear, which left used_bytes_ stale while size() read zero.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants