From 61d7279e1f13887b30335c89abdc8a947f0ae814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Wed, 16 Jul 2025 16:00:39 +0300 Subject: [PATCH] trie: avoid spawning goroutines for empty children (#32220) --- trie/hasher.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/trie/hasher.go b/trie/hasher.go index 393cb0bd4d..16606808c9 100644 --- a/trie/hasher.go +++ b/trie/hasher.go @@ -105,18 +105,18 @@ func (h *hasher) hashFullNodeChildren(n *fullNode) *fullNode { var children [17]node if h.parallel { var wg sync.WaitGroup - wg.Add(16) for i := 0; i < 16; i++ { - go func(i int) { - hasher := newHasher(false) - if child := n.Children[i]; child != nil { + if child := n.Children[i]; child != nil { + wg.Add(1) + go func(i int) { + hasher := newHasher(false) children[i] = hasher.hash(child, false) - } else { - children[i] = nilValueNode - } - returnHasherToPool(hasher) - wg.Done() - }(i) + returnHasherToPool(hasher) + wg.Done() + }(i) + } else { + children[i] = nilValueNode + } } wg.Wait() } else {