Skip to content

Commit 5f72608

Browse files
authored
Reduce memcpy when writting changesets (#17659)
Small optimization, on mainnet it is harmless, but on bloatnet I see 9K-12K chunks per block (1 chunk == 4KB).
1 parent be8acae commit 5f72608

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

db/state/changeset/state_changeset.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,15 @@ func WriteDiffSet(tx kv.RwTx, blockNumber uint64, blockHash common.Hash, diffSet
219219
}
220220

221221
key := make([]byte, DiffChunkKeyLen)
222+
binary.BigEndian.PutUint64(key, blockNumber)
223+
copy(key[8:], blockHash[:])
224+
222225
for i := 0; i < chunkCount; i++ {
223226
start := i * DiffChunkLen
224227
end := (i + 1) * DiffChunkLen
225228
if end > len(keys) {
226229
end = len(keys)
227230
}
228-
binary.BigEndian.PutUint64(key, blockNumber)
229-
copy(key[8:], blockHash[:])
230231
binary.BigEndian.PutUint64(key[40:], uint64(i))
231232

232233
if err := tx.Put(kv.ChangeSets3, key, keys[start:end]); err != nil {

0 commit comments

Comments
 (0)