From ca1e6b3fb46ecf9f7c7054e20f286e64523f0fde Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 26 Dec 2019 11:15:13 +0100 Subject: [PATCH] core/state: minor optimization in state onleaf allocation --- core/state/statedb.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index 03e118d117..8399f1bab9 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -750,8 +750,10 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) { if metrics.EnabledExpensive { defer func(start time.Time) { s.AccountCommits += time.Since(start) }(time.Now()) } + // The onleaf func is called _serially_, so we can reuse the same account + // for unmarshalling every time. + var account Account return s.trie.Commit(func(leaf []byte, parent common.Hash) error { - var account Account if err := rlp.DecodeBytes(leaf, &account); err != nil { return nil }