mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
trie: preallocate slice capacity (#33689)
This PR optimizes memory allocation in StateTrie.PrefetchAccount() and StateTrie.PrefetchStorage() by preallocating slice capacity when the final size is known.
This commit is contained in:
parent
c2595381bf
commit
e250836973
1 changed files with 6 additions and 6 deletions
|
|
@ -134,9 +134,9 @@ func (t *StateTrie) GetAccountByHash(addrHash common.Hash) (*types.StateAccount,
|
||||||
// PrefetchAccount attempts to resolve specific accounts from the database
|
// PrefetchAccount attempts to resolve specific accounts from the database
|
||||||
// to accelerate subsequent trie operations.
|
// to accelerate subsequent trie operations.
|
||||||
func (t *StateTrie) PrefetchAccount(addresses []common.Address) error {
|
func (t *StateTrie) PrefetchAccount(addresses []common.Address) error {
|
||||||
var keys [][]byte
|
keys := make([][]byte, len(addresses))
|
||||||
for _, addr := range addresses {
|
for i, addr := range addresses {
|
||||||
keys = append(keys, crypto.Keccak256(addr.Bytes()))
|
keys[i] = crypto.Keccak256(addr.Bytes())
|
||||||
}
|
}
|
||||||
return t.trie.Prefetch(keys)
|
return t.trie.Prefetch(keys)
|
||||||
}
|
}
|
||||||
|
|
@ -157,9 +157,9 @@ func (t *StateTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {
|
||||||
// PrefetchStorage attempts to resolve specific storage slots from the database
|
// PrefetchStorage attempts to resolve specific storage slots from the database
|
||||||
// to accelerate subsequent trie operations.
|
// to accelerate subsequent trie operations.
|
||||||
func (t *StateTrie) PrefetchStorage(_ common.Address, keys [][]byte) error {
|
func (t *StateTrie) PrefetchStorage(_ common.Address, keys [][]byte) error {
|
||||||
var keylist [][]byte
|
keylist := make([][]byte, len(keys))
|
||||||
for _, key := range keys {
|
for i, key := range keys {
|
||||||
keylist = append(keylist, crypto.Keccak256(key))
|
keylist[i] = crypto.Keccak256(key)
|
||||||
}
|
}
|
||||||
return t.trie.Prefetch(keylist)
|
return t.trie.Prefetch(keylist)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue