Skip to content

Commit abf893a

Browse files
Add changelog entries for pooled cache stores
1 parent a33a22f commit abf893a

File tree

6 files changed

+26
-2
lines changed

6 files changed

+26
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4242

4343
* (baseapp) [#24655](https://github.com/cosmos/cosmos-sdk/pull/24655) Add mutex locks for `state` and make `lastCommitInfo` atomic to prevent race conditions between `Commit` and `CreateQueryContext`.
4444
* (proto) [#24161](https://github.com/cosmos/cosmos-sdk/pull/24161) Remove unnecessary annotations from `x/staking` authz proto.
45+
* (baseapp) [#24608](https://github.com/cosmos/cosmos-sdk/pull/24608) Use a `PooledCacheMultiStore` in `cacheTxContext` to prevent allocating a new cache for every transaction.
4546

4647
### Bug Fixes
4748

store/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
2323

2424
# Changelog
2525

26+
## [Unreleased]
27+
28+
### Improvements
29+
30+
* [#24608](https://github.com/cosmos/cosmos-sdk/pull/24608) Introduced pooled versions of cache stores to avoid allocating new caches.
31+
2632
## v1.1.2 (March 31, 2025)
2733

2834
### Bug Fixes

store/cachekv/internal/btree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func NewBTree() BTree {
3636
}
3737
}
3838

39-
// Clear clears the tree.
39+
// Clear resets the tree by setting the root node to nil, dropping all items.
4040
func (bt BTree) Clear() {
4141
bt.tree.Clear()
4242
}

store/cachekv/store.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ type PooledStore struct {
3838
Store
3939
}
4040

41-
var _ types.CacheKVStore = (*Store)(nil)
41+
var (
42+
_ types.CacheKVStore = (*Store)(nil)
43+
_ types.PooledCacheKVStore = (*PooledStore)(nil)
44+
)
4245

4346
// NewStore creates a new Store object
4447
func NewStore(parent types.KVStore) *Store {
@@ -50,6 +53,10 @@ func NewStore(parent types.KVStore) *Store {
5053
}
5154
}
5255

56+
// storePool is a pool of PooledStore instances. It contains a set of objects
57+
// that can be reused instead of allocating new ones. It's thread safe.
58+
// Callers can use Get() to retrieve a store (or allocate a new one if none are available).
59+
// Callers should use Put() when done with the store to return it to the pool.
5360
var storePool = sync.Pool{
5461
New: func() any {
5562
return &PooledStore{

store/cachemulti/store.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ func NewStore(
8383
return NewFromKVStore(dbadapter.Store{DB: db}, stores, keys, traceWriter, traceContext)
8484
}
8585

86+
// storePool is a pool of PooledStore instances. It contains a set of objects
87+
// that can be reused instead of allocating new ones. It's thread safe.
88+
// Callers can use Get() to retrieve a store (or allocate a new one if none are available).
89+
// Callers should use Put() when done with the store to return it to the pool.
8690
var storePool = sync.Pool{
8791
New: func() any {
8892
return &PooledStore{

store/types/store.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ type CacheKVStore interface {
288288
Write()
289289
}
290290

291+
// PooledCacheKVStore is a CacheKVStore that can be pooled and reused without the overhead of allocation.
292+
type PooledCacheKVStore interface {
293+
CacheKVStore
294+
Release()
295+
}
296+
291297
// CommitKVStore is an interface for MultiStore.
292298
type CommitKVStore interface {
293299
Committer

0 commit comments

Comments
 (0)