mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +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
|
||||
// to accelerate subsequent trie operations.
|
||||
func (t *StateTrie) PrefetchAccount(addresses []common.Address) error {
|
||||
var keys [][]byte
|
||||
for _, addr := range addresses {
|
||||
keys = append(keys, crypto.Keccak256(addr.Bytes()))
|
||||
keys := make([][]byte, len(addresses))
|
||||
for i, addr := range addresses {
|
||||
keys[i] = crypto.Keccak256(addr.Bytes())
|
||||
}
|
||||
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
|
||||
// to accelerate subsequent trie operations.
|
||||
func (t *StateTrie) PrefetchStorage(_ common.Address, keys [][]byte) error {
|
||||
var keylist [][]byte
|
||||
for _, key := range keys {
|
||||
keylist = append(keylist, crypto.Keccak256(key))
|
||||
keylist := make([][]byte, len(keys))
|
||||
for i, key := range keys {
|
||||
keylist[i] = crypto.Keccak256(key)
|
||||
}
|
||||
return t.trie.Prefetch(keylist)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue