mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
trie: parallel commit
This commit is contained in:
parent
be92f5487e
commit
8e8031c107
1 changed files with 15 additions and 9 deletions
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue