mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-03-21 18:38:07 +00:00
## Summary At tree depths below `log2(NumCPU)` (clamped to [2, 8]), hash the left subtree in a goroutine while hashing the right subtree inline. This exploits available CPU cores for the top levels of the tree where subtree hashing is most expensive. On single-core machines, the parallel path is disabled entirely. Deeper nodes use sequential hashing with the existing `sync.Pool` hasher where goroutine overhead would exceed the hash computation cost. The parallel path uses `sha256.Sum256` with a stack-allocated buffer to avoid pool contention across goroutines. **Safety:** - Left/right subtrees are disjoint — no shared mutable state - `sync.WaitGroup` provides happens-before guarantee for the result - `defer wg.Done()` + `recover()` prevents goroutine panics from crashing the process - `!bt.mustRecompute` early return means clean nodes never enter the parallel path - Hash results are deterministic regardless of computation order — no consensus risk ## Benchmark (AMD EPYC 48-core, 500K entries, `--benchtime=10s --count=3`, post-H01 baseline) | Metric | Baseline | Parallel | Delta | |--------|----------|----------|-------| | Approve (Mgas/s) | 224.5 ± 7.1 | **259.6 ± 2.4** | **+15.6%** | | BalanceOf (Mgas/s) | 982.9 ± 5.1 | 954.3 ± 10.8 | -2.9% (noise, clean nodes skip parallel path) | | Allocs/op (approve) | ~810K | ~700K | -13.6% | |
||
|---|---|---|
| .. | ||
| bintrie | ||
| transitiontrie | ||
| trienode | ||
| bytepool.go | ||
| committer.go | ||
| database_test.go | ||
| encoding.go | ||
| encoding_test.go | ||
| errors.go | ||
| hasher.go | ||
| inspect.go | ||
| inspect_test.go | ||
| iterator.go | ||
| iterator_test.go | ||
| levelstats.go | ||
| levelstats_test.go | ||
| list_hasher.go | ||
| node.go | ||
| node_enc.go | ||
| node_test.go | ||
| proof.go | ||
| proof_test.go | ||
| secure_trie.go | ||
| secure_trie_test.go | ||
| stacktrie.go | ||
| stacktrie_fuzzer_test.go | ||
| stacktrie_test.go | ||
| sync.go | ||
| sync_test.go | ||
| tracer.go | ||
| tracer_test.go | ||
| trie.go | ||
| trie_id.go | ||
| trie_reader.go | ||
| trie_test.go | ||