mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-14 10:51:35 +00:00
The pooled hash.Hash interface forced the local [StemNodeWidth]common.Hash data array to escape to the heap: h.Sum(data[i][:0]) passes a subslice of data into an interface method, so escape analysis conservatively moves the whole array. pprof (post-rollback) showed this single allocation as 52% of total bytes (5 GB over BenchmarkCollectNodesSparseWrite). Switch to sha256.Sum256 (takes []byte, returns [32]byte by value) — no slice into data ever leaves the frame, so data stays on stack. Also drops per-Hash h.Sum(nil) allocs and the sync.Pool Get/Put round-trip for stems. Benchmark delta (M4 Pro, go1.24.0, --count=5 --benchtime=5s): before: 9095 ns/op 15008 B/op 106 allocs/op after: 9133 ns/op 6526 B/op 95 allocs/op vs upstream/master@53ff723cc: bytes/op -82.7% (was -60%), allocs/op -29.1% (was -20.9%). |
||
|---|---|---|
| .. | ||
| binary_node.go | ||
| binary_node_test.go | ||
| hashed_node.go | ||
| hashed_node_test.go | ||
| hasher.go | ||
| internal_node.go | ||
| internal_node_test.go | ||
| iterator.go | ||
| iterator_test.go | ||
| key_encoding.go | ||
| node_ref.go | ||
| node_store.go | ||
| stem_node.go | ||
| stem_node_test.go | ||
| store_commit.go | ||
| store_ops.go | ||
| trie.go | ||
| trie_test.go | ||