perf(store): replace sync.Map with plain map in cachekv stores#2822
perf(store): replace sync.Map with plain map in cachekv stores#2822pdrobnjak wants to merge 1 commit intoperf/remove-vis-sortedstorefrom
Conversation
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
2f8f30d to
024e61c
Compare
0e0765c to
3171cd1
Compare
| for key, cv := range store.cache { | ||
| // Replace with a clean (non-dirty) version of the same value | ||
| store.cache.Store(key, types.NewCValue(cv.Value(), false)) | ||
| return true | ||
| }) | ||
| store.cache[key] = types.NewCValue(cv.Value(), false) | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
| for key, cv := range store.cache { | ||
| kbz := []byte(key) | ||
| if bytes.Compare(kbz, start) < 0 || bytes.Compare(kbz, end) >= 0 { | ||
| // we don't want to break out of the iteration since cache isn't sorted | ||
| return true | ||
| continue | ||
| } | ||
| cv := value.(*types.CValue) | ||
| if cv.Value() == nil { | ||
| delete(keyStrs, key.(string)) | ||
| delete(keyStrs, key) | ||
| } else { | ||
| keyStrs[key.(string)] = struct{}{} | ||
| keyStrs[key] = struct{}{} | ||
| } | ||
| return true | ||
| }) | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
| for cKey := range store.unsortedCache { | ||
| if dbm.IsKeyInDomain(conv.UnsafeStrToBytes(cKey), start, end) { | ||
| cacheValue, ok := store.cache.Load(key) | ||
| if ok { | ||
| unsorted = append(unsorted, &kv.Pair{Key: []byte(cKey), Value: cacheValue.(*types.CValue).Value()}) | ||
| if cacheValue, ok := store.cache[cKey]; ok { | ||
| unsorted = append(unsorted, &kv.Pair{Key: []byte(cKey), Value: cacheValue.Value()}) | ||
| } | ||
| } | ||
| return true | ||
| }) | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
| for key, cv := range store.cache { | ||
| kbz := []byte(key) | ||
| if bytes.Compare(kbz, start) < 0 || bytes.Compare(kbz, end) >= 0 { | ||
| // we don't want to break out of the iteration since cache isn't sorted | ||
| return true | ||
| continue | ||
| } | ||
| cv := value.(*types.CValue) | ||
| if cv.Value() == nil { | ||
| delete(keyStrs, key.(string)) | ||
| delete(keyStrs, key) | ||
| } else { | ||
| keyStrs[key.(string)] = struct{}{} | ||
| keyStrs[key] = struct{}{} | ||
| } | ||
| return true | ||
| }) | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
024e61c to
19fc5b8
Compare
3171cd1 to
7ddc9f6
Compare
19fc5b8 to
f6066c0
Compare
7ddc9f6 to
915aaaf
Compare
f6066c0 to
f2970af
Compare
Within OCC, each worker gets its own CacheMultiStore chain with
dedicated cachekv.Store instances — zero concurrent access. The
sync.Map thread-safety overhead (CAS, internal node allocs) is
pure waste in this single-goroutine context.
Replace *sync.Map with typed Go maps in both sei-cosmos and giga
cachekv implementations:
- cache: map[string]*types.CValue
- deleted: map[string]struct{}
- unsortedCache: map[string]struct{}
Keep sync.RWMutex for defense-in-depth (uncontested, <20ns).
Micro-benchmarks: 32-56% faster across all cachekv operations,
4 allocs/op eliminated from Set paths.
TPS benchmark: ~8,936 avg (+14.6% cumulative over origin/main).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
915aaaf to
6ab07c6
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## perf/remove-vis-sortedstore #2822 +/- ##
===============================================================
- Coverage 56.67% 46.95% -9.73%
===============================================================
Files 2031 1965 -66
Lines 165978 160637 -5341
===============================================================
- Hits 94074 75432 -18642
- Misses 63660 78667 +15007
+ Partials 8244 6538 -1706
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Summary
*sync.Mapwith typed Go maps (map[string]*types.CValue,map[string]struct{}) in both sei-cosmos and giga cachekv implementationsnewIndirectNode,newEntryNode)sync.RWMutexfor defense-in-depth (uncontested, <20ns)Files changed:
sei-cosmos/store/cachekv/store.go,sei-cosmos/store/cachekv/memiterator.go,giga/deps/store/cachekv.goMicro-benchmarks (cachekv, 3 runs)
4 allocs/op eliminated from Set paths — exactly the sync.Map internal node allocations.
TPS benchmark (GIGA+OCC, EVMTransfer 1000 txs/batch)
Cumulative from origin/main
Test plan
sei-cosmos/store/cachekvtests (11 tests pass)sei-cosmos/store/...full suite (15 packages pass)giga/tests(all pass)gofmt -s -lclean🤖 Generated with Claude Code