Skip to content

Commit 3c1443e

Browse files
committed
triedb/pathdb: use copy instead of append to reduce memory alloc
Signed-off-by: jsvisa <[email protected]>
1 parent 739f6f4 commit 3c1443e

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

triedb/pathdb/disklayer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ func (dl *diskLayer) storage(accountHash, storageHash common.Hash, depth int) ([
275275

276276
// If the layer is being generated, ensure the requested storage slot
277277
// has already been covered by the generator.
278-
key := append(accountHash[:], storageHash[:]...)
278+
skey := storageKey(accountHash, storageHash)
279+
key := skey[:]
279280
marker := dl.genMarker()
280281
if marker != nil && bytes.Compare(key, marker) > 0 {
281282
return nil, errNotCoveredYet

triedb/pathdb/flush.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,17 @@ func writeStates(batch ethdb.Batch, genMarker []byte, accountData map[common.Has
116116
continue
117117
}
118118
slots += 1
119+
skey := storageKey(addrHash, storageHash)
120+
key := skey[:]
119121
if len(blob) == 0 {
120122
rawdb.DeleteStorageSnapshot(batch, addrHash, storageHash)
121123
if clean != nil {
122-
clean.Set(append(addrHash[:], storageHash[:]...), nil)
124+
clean.Set(key, nil)
123125
}
124126
} else {
125127
rawdb.WriteStorageSnapshot(batch, addrHash, storageHash, blob)
126128
if clean != nil {
127-
clean.Set(append(addrHash[:], storageHash[:]...), blob)
129+
clean.Set(key, blob)
128130
}
129131
}
130132
}

0 commit comments

Comments
 (0)