This commit is contained in:
Marius van der Wijden 2026-05-21 21:55:08 -07:00 committed by GitHub
commit 4dd39b9278
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -88,8 +88,7 @@ func (c *committer) commit(path []byte, n node, parallel bool) node {
// commitChildren commits the children of the given fullnode
func (c *committer) commitChildren(path []byte, n *fullNode, parallel bool) {
var (
wg sync.WaitGroup
nodesMu sync.Mutex
index = make([]int, 0, 16)
)
for i := 0; i < 16; i++ {
child := n.Children[i]
@ -102,28 +101,35 @@ func (c *committer) commitChildren(path []byte, n *fullNode, parallel bool) {
if _, ok := child.(hashNode); ok {
continue
}
index = append(index, i)
}
if !parallel {
// Commit the child recursively and store the "hashed" value.
// Note the returned node can be some embedded nodes, so it's
// possible the type is not hashNode.
if !parallel {
n.Children[i] = c.commit(append(path, byte(i)), child, false)
} else {
wg.Add(1)
for _, i := range index {
n.Children[i] = c.commit(append(path, byte(i)), n.Children[i], false)
}
} else {
var (
wg sync.WaitGroup
nodesMu sync.Mutex
)
wg.Add(len(index))
for _, i := range index {
go func(index int) {
defer wg.Done()
p := append(path, byte(index))
childSet := trienode.NewNodeSet(c.nodes.Owner)
childCommitter := newCommitter(childSet, c.tracer, c.collectLeaf)
n.Children[index] = childCommitter.commit(p, child, false)
n.Children[index] = childCommitter.commit(p, n.Children[i], false)
nodesMu.Lock()
c.nodes.MergeDisjoint(childSet)
nodesMu.Unlock()
}(i)
}
}
if parallel {
wg.Wait()
}
}