triedb/pathdb: use copy instead of append to reduce memory alloc (#33044)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

This commit is contained in:
Delweng 2025-12-11 09:37:16 +08:00 committed by GitHub
parent b98b255449
commit 1b702f71d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 3 deletions

View file

@ -275,7 +275,7 @@ func (dl *diskLayer) storage(accountHash, storageHash common.Hash, depth int) ([
// If the layer is being generated, ensure the requested storage slot // If the layer is being generated, ensure the requested storage slot
// has already been covered by the generator. // has already been covered by the generator.
key := append(accountHash[:], storageHash[:]...) key := storageKeySlice(accountHash, storageHash)
marker := dl.genMarker() marker := dl.genMarker()
if marker != nil && bytes.Compare(key, marker) > 0 { if marker != nil && bytes.Compare(key, marker) > 0 {
return nil, errNotCoveredYet return nil, errNotCoveredYet

View file

@ -116,15 +116,16 @@ func writeStates(batch ethdb.Batch, genMarker []byte, accountData map[common.Has
continue continue
} }
slots += 1 slots += 1
key := storageKeySlice(addrHash, storageHash)
if len(blob) == 0 { if len(blob) == 0 {
rawdb.DeleteStorageSnapshot(batch, addrHash, storageHash) rawdb.DeleteStorageSnapshot(batch, addrHash, storageHash)
if clean != nil { if clean != nil {
clean.Set(append(addrHash[:], storageHash[:]...), nil) clean.Set(key, nil)
} }
} else { } else {
rawdb.WriteStorageSnapshot(batch, addrHash, storageHash, blob) rawdb.WriteStorageSnapshot(batch, addrHash, storageHash, blob)
if clean != nil { if clean != nil {
clean.Set(append(addrHash[:], storageHash[:]...), blob) clean.Set(key, blob)
} }
} }
} }

View file

@ -33,6 +33,13 @@ func storageKey(accountHash common.Hash, slotHash common.Hash) [64]byte {
return key return key
} }
// storageKeySlice returns a key for uniquely identifying the storage slot in
// the slice format.
func storageKeySlice(accountHash common.Hash, slotHash common.Hash) []byte {
key := storageKey(accountHash, slotHash)
return key[:]
}
// lookup is an internal structure used to efficiently determine the layer in // lookup is an internal structure used to efficiently determine the layer in
// which a state entry resides. // which a state entry resides.
type lookup struct { type lookup struct {