From bf893cb73b44c4215e291ee547d728a685050709 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Wed, 16 Apr 2025 17:08:31 +0800 Subject: [PATCH] trie: reduce allocs in insertPreimage (#21261) (#943) Co-authored-by: Marius van der Wijden --- trie/database.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/trie/database.go b/trie/database.go index f9c108907c..eafa9f60c0 100644 --- a/trie/database.go +++ b/trie/database.go @@ -323,15 +323,16 @@ func (db *Database) insert(hash common.Hash, size int, node node) { db.dirtiesSize += common.StorageSize(common.HashLength + entry.size) } -// InsertPreimage writes a new trie Node pre-image to the memory database if it's -// yet unknown. The method will make a copy of the slice. +// insertPreimage writes a new trie node pre-image to the memory database if it's +// yet unknown. The method will NOT make a copy of the slice, +// only use if the preimage will NOT be changed later on. // // Note, this method assumes that the database's Lock is held! func (db *Database) InsertPreimage(hash common.Hash, preimage []byte) { if _, ok := db.preimages[hash]; ok { return } - db.preimages[hash] = common.CopyBytes(preimage) + db.preimages[hash] = preimage db.preimagesSize += common.StorageSize(common.HashLength + len(preimage)) }