Skip to content

Commit 8b8c926

Browse files
omerfirmakucwong
authored andcommitted
trie: avoid spawning goroutines for empty children (#32220)
1 parent 120fb79 commit 8b8c926

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

trie/hasher.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,18 @@ func (h *hasher) hashFullNodeChildren(n *fullNode) *fullNode {
113113
var children [17]node
114114
if h.parallel {
115115
var wg sync.WaitGroup
116-
wg.Add(16)
117116
for i := 0; i < 16; i++ {
118-
go func(i int) {
119-
hasher := newHasher(false)
120-
if child := n.Children[i]; child != nil {
117+
if child := n.Children[i]; child != nil {
118+
wg.Add(1)
119+
go func(i int) {
120+
hasher := newHasher(false)
121121
children[i] = hasher.hash(child, false)
122-
} else {
123-
children[i] = nilValueNode
124-
}
125-
returnHasherToPool(hasher)
126-
wg.Done()
127-
}(i)
122+
returnHasherToPool(hasher)
123+
wg.Done()
124+
}(i)
125+
} else {
126+
children[i] = nilValueNode
127+
}
128128
}
129129
wg.Wait()
130130
} else {

0 commit comments

Comments
 (0)