mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-14 03:56:36 +00:00
triedb/pathdb: use copy instead of append to reduce memory alloc (#33044)
This commit is contained in:
parent
b98b255449
commit
1b702f71d9
3 changed files with 11 additions and 3 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue