From ee02c0a277b9456dbefad786db5b708c10eb7c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20IRMAK?= Date: Tue, 15 Jul 2025 19:23:49 +0300 Subject: [PATCH] trie: reduce allocations in hashFullNodeChildren temporary children array espaces to heap. Directly hash into a fullNode instead. --- trie/hasher.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/trie/hasher.go b/trie/hasher.go index 393cb0bd4d..de3ccce0fc 100644 --- a/trie/hasher.go +++ b/trie/hasher.go @@ -102,7 +102,7 @@ func (h *hasher) hashShortNodeChildren(n *shortNode) *shortNode { // hashFullNodeChildren returns a copy of the supplied fullNode, with its child // being replaced by either the hash or an embedded node if the child is small. func (h *hasher) hashFullNodeChildren(n *fullNode) *fullNode { - var children [17]node + fullNode := fullNode{flags: nodeFlag{}} if h.parallel { var wg sync.WaitGroup wg.Add(16) @@ -110,9 +110,9 @@ func (h *hasher) hashFullNodeChildren(n *fullNode) *fullNode { go func(i int) { hasher := newHasher(false) if child := n.Children[i]; child != nil { - children[i] = hasher.hash(child, false) + fullNode.Children[i] = hasher.hash(child, false) } else { - children[i] = nilValueNode + fullNode.Children[i] = nilValueNode } returnHasherToPool(hasher) wg.Done() @@ -122,16 +122,16 @@ func (h *hasher) hashFullNodeChildren(n *fullNode) *fullNode { } else { for i := 0; i < 16; i++ { if child := n.Children[i]; child != nil { - children[i] = h.hash(child, false) + fullNode.Children[i] = h.hash(child, false) } else { - children[i] = nilValueNode + fullNode.Children[i] = nilValueNode } } } if n.Children[16] != nil { - children[16] = n.Children[16] + fullNode.Children[16] = n.Children[16] } - return &fullNode{flags: nodeFlag{}, Children: children} + return &fullNode } // shortNodeToHash computes the hash of the given shortNode. The shortNode must