perf(types): cache gaskv.Store wrappers in Context#2808
Merged
pdrobnjak merged 0 commit intoperf/lazy-cachemultistorefrom Feb 11, 2026
Merged
perf(types): cache gaskv.Store wrappers in Context#2808pdrobnjak merged 0 commit intoperf/lazy-cachemultistorefrom
pdrobnjak merged 0 commit intoperf/lazy-cachemultistorefrom
Conversation
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## perf/lazy-cachemultistore #2808 +/- ##
=============================================================
+ Coverage 52.28% 56.67% +4.39%
=============================================================
Files 1030 2031 +1001
Lines 85199 165964 +80765
=============================================================
+ Hits 44546 94065 +49519
- Misses 36523 63657 +27134
- Partials 4130 8242 +4112
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
4 tasks
f95aa5e to
b620ffb
Compare
b620ffb to
13f343e
Compare
de7b59d to
f1c3021
Compare
d52d4a1 to
cc0301f
Compare
Contributor
Author
|
This PR was auto-merged by GitHub during a stack reorder (branch force-push made head appear merged into base). No code was actually merged to main. This PR has been superseded — see the restacked PR chain starting at #2849. |
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 amap[StoreKey]KVStoreonContext, eliminating repeated heap allocations fromctx.KVStore(key)andctx.TransientStore(key)WithMultiStore/WithGasMeter(the only methods that change gaskv inputs)Problem
Every
ctx.KVStore(key)andctx.TransientStore(key)call allocates a newgaskv.Storeon the heap (5-field struct, ~40 bytes). Each wraps the same underlying KVStore + same gas meter + same gas config — pure waste to reallocate.Profiling after #2806 (30s, M4 Max, 1000 EVM transfers/block):
gaskv.NewStorealloc_spacegaskv.NewStorealloc_objectsAccountKeeper.GetAccount(104.5M),params.Subspace.kvStore(46.6M),bank.getAccountStore(20.7M)Changes
sei-cosmos/types/context.go(single file):gaskvStores map[StoreKey]KVStoreon Context structNewContext: Initialize cache withmake(map[StoreKey]KVStore, 8)WithMultiStore/WithGasMeter: Invalidate cache (new empty map)KVStore/TransientStore: Check cache first; populate on missBenchmark Results (M4 Max, 1000 EVM transfers/block, 30s profile)
gaskv.NewStorealloc_spacegaskv.NewStorealloc_objectsmemclrNoHeapPointersCPUbtree.NewFreeListGallocsync.Map nodesalloccachemulti.newStoreWithoutGigaallocNote: TPS uplift is modest because freed CPU shifts to idle (usleep/kevent up) — workers complete faster but the bottleneck has shifted elsewhere (likely OCC scheduling / commit pipeline).
pprof -alloc_space -diff_basehighlightspprof -top -diff_basehighlights (CPU)Why safe
MultiStore(),GasMeter(),StoreTracer()are stableKVGasConfig()/TransientGasConfig()return constantsWithMultiStoreandWithGasMeterare the only methods that change gaskv inputs — both invalidateTest plan
go test github.com/cosmos/cosmos-sdk/types -count=1— passgo test ./giga/tests/... -count=1— pass (all 14 giga tests)go test ./sei-cosmos/store/cachemulti/... -count=1— passgofmt -s -wclean🤖 Generated with Claude Code