mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-12 01:41:36 +00:00
trie/bintrie: compute parallelHashDepth once at init
runtime.NumCPU() + bits.Len were recomputed on every hashInternal call. NumCPU is immutable after startup; hoist to a package var computed once. Also fixes a minor style wart: the constant is now a value, not a zero-arg function.
This commit is contained in:
parent
f8c283410e
commit
6e36636c9c
1 changed files with 7 additions and 9 deletions
|
|
@ -48,26 +48,24 @@ func (s *NodeStore) computeHash(ref nodeRef) common.Hash {
|
|||
}
|
||||
}
|
||||
|
||||
// parallelDepth returns the tree depth below which hashInternal spawns
|
||||
// goroutines for shallow-depth parallelism.
|
||||
func parallelDepth() int {
|
||||
return min(bits.Len(uint(runtime.NumCPU())), 8)
|
||||
}
|
||||
// parallelHashDepth is the tree depth below which hashInternal spawns
|
||||
// goroutines for shallow-depth parallelism. Computed once at init because
|
||||
// NumCPU() never changes after startup.
|
||||
var parallelHashDepth = min(bits.Len(uint(runtime.NumCPU())), 8)
|
||||
|
||||
// hashInternal hashes an InternalNode and caches the result.
|
||||
//
|
||||
// At shallow depths (< parallelDepth()) the left subtree is hashed in a
|
||||
// At shallow depths (< parallelHashDepth) the left subtree is hashed in a
|
||||
// goroutine while the right subtree is hashed inline, then the two digests
|
||||
// are combined. Below that threshold the goroutine spawn cost outweighs the
|
||||
// hashing work, so deeper nodes hash both children sequentially via the
|
||||
// pooled hasher.
|
||||
// hashing work, so deeper nodes hash both children sequentially.
|
||||
func (s *NodeStore) hashInternal(idx uint32) common.Hash {
|
||||
node := s.getInternal(idx)
|
||||
if !node.mustRecompute {
|
||||
return node.hash
|
||||
}
|
||||
|
||||
if int(node.depth) < parallelDepth() {
|
||||
if int(node.depth) < parallelHashDepth {
|
||||
var input [64]byte
|
||||
var lh common.Hash
|
||||
var wg sync.WaitGroup
|
||||
|
|
|
|||
Loading…
Reference in a new issue