mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
triedb: opt using sync.Pool
This commit is contained in:
parent
c3ef6c77c2
commit
be3291c015
1 changed files with 10 additions and 2 deletions
|
|
@ -161,6 +161,12 @@ func (l *lookup) storageTip(accountHash common.Hash, slotHash common.Hash, state
|
||||||
return common.Hash{}
|
return common.Hash{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var listPool = sync.Pool{
|
||||||
|
New: func() any {
|
||||||
|
return make([]common.Hash, 0, 16)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// addLayer traverses the state data retained in the specified diff layer and
|
// addLayer traverses the state data retained in the specified diff layer and
|
||||||
// integrates it into the lookup set.
|
// integrates it into the lookup set.
|
||||||
//
|
//
|
||||||
|
|
@ -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 = listPool.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 = listPool.Get().([]common.Hash)
|
||||||
}
|
}
|
||||||
list = append(list, state)
|
list = append(list, state)
|
||||||
l.storages[key] = list
|
l.storages[key] = list
|
||||||
|
|
@ -251,6 +257,7 @@ func (l *lookup) removeLayer(diff *diffLayer) error {
|
||||||
if len(list) != 0 {
|
if len(list) != 0 {
|
||||||
l.accounts[accountHash] = list
|
l.accounts[accountHash] = list
|
||||||
} else {
|
} else {
|
||||||
|
listPool.Put(list[:0])
|
||||||
delete(l.accounts, accountHash)
|
delete(l.accounts, accountHash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -268,6 +275,7 @@ func (l *lookup) removeLayer(diff *diffLayer) error {
|
||||||
if len(list) != 0 {
|
if len(list) != 0 {
|
||||||
l.storages[key] = list
|
l.storages[key] = list
|
||||||
} else {
|
} else {
|
||||||
|
listPool.Put(list[:0])
|
||||||
delete(l.storages, key)
|
delete(l.storages, key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue