triedb: use sync pool

This commit is contained in:
rrhlrmrr 2025-07-08 14:11:06 +09:00
parent b3131f00a3
commit 695545b49b

View file

@ -25,6 +25,12 @@ import (
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
var hashSlicePool = sync.Pool{
New: func() interface{} {
return make([]common.Hash, 0, 16)
},
}
// storageKey returns a key for uniquely identifying the storage slot. // storageKey returns a key for uniquely identifying the storage slot.
func storageKey(accountHash common.Hash, slotHash common.Hash) [64]byte { func storageKey(accountHash common.Hash, slotHash common.Hash) [64]byte {
var key [64]byte var key [64]byte
@ -182,7 +188,7 @@ func (l *lookup) addLayer(diff *diffLayer) {
for accountHash := range diff.states.accountData { for accountHash := range diff.states.accountData {
list, exists := l.accounts[accountHash] list, exists := l.accounts[accountHash]
if !exists { if !exists {
list = make([]common.Hash, 0, 16) // TODO(rjl493456442) use sync pool list = hashSlicePool.Get().([]common.Hash)
} }
list = append(list, state) list = append(list, state)
l.accounts[accountHash] = list l.accounts[accountHash] = list
@ -197,7 +203,7 @@ func (l *lookup) addLayer(diff *diffLayer) {
key := storageKey(accountHash, slotHash) key := storageKey(accountHash, slotHash)
list, exists := l.storages[key] list, exists := l.storages[key]
if !exists { if !exists {
list = make([]common.Hash, 0, 16) // TODO(rjl493456442) use sync pool list = hashSlicePool.Get().([]common.Hash)
} }
list = append(list, state) list = append(list, state)
l.storages[key] = list l.storages[key] = list