perf(types): cache gaskv.Store wrappers in Context#2853
Draft
perf(types): cache gaskv.Store wrappers in Context#2853
Conversation
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
Every ctx.KVStore(key) / ctx.TransientStore(key) call was allocating a new gaskv.Store on the heap (~40 bytes, 5 fields). Profiling showed 155M allocations / 18.9 GB from gaskv.NewStore over 30s, with top callers being AccountKeeper.GetAccount (104.5M), params.Subspace (46.6M), and bank.getAccountStore (20.7M). Each wraps the same underlying KVStore, gas meter, and gas config — pure waste to reallocate. Add a gaskvStores map[StoreKey]KVStore cache to Context. On first KVStore(key) call, create and cache. On subsequent calls, return cached. Cache is invalidated (fresh empty map) in WithMultiStore and WithGasMeter, which are the only methods that change gaskv.NewStore inputs. Results (M4 Max benchmark): - gaskv.NewStore completely eliminated from heap profiles (-18.3 GB) - Cascading reductions: cachemulti -17.4 GB, btree -16.5 GB - TPS steady-state: 7,800-9,000 (median ~8,400) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The gaskvStores cache map on Context is read/written concurrently when multiple goroutines share a Context (e.g., slashing BeginBlocker's HandleValidatorSignatureConcurrent). Add *sync.RWMutex with RLock for cache hits, Lock for cache misses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
WithIsTracing changes how gaskv.Store wraps the underlying store (tracing vs non-tracing). Cached stores created before tracing was enabled would miss trace events. Reset the cache on tracing change. Fixes TestViewKeeperStoreTrace failure introduced by gaskv caching. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
f1c3021 to
a4c49dc
Compare
de1b10e to
9581921
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2853 +/- ##
===========================================
+ Coverage 46.28% 56.77% +10.49%
===========================================
Files 2005 2070 +65
Lines 163018 168332 +5314
===========================================
+ Hits 75449 95577 +20128
+ Misses 81047 64261 -16786
- Partials 6522 8494 +1972
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gaskv.Storewrappers in Context to avoid repeated allocationsStack
6/19 — depends on perf/optimize-updatereadset-alloc (replaces auto-closed #2808)
🤖 Generated with Claude Code