go-ethereum/trie/bintrie
CPerezz ef3217c249
trie/bintrie: keep StemNode.Hash's data array on stack
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%).
2026-04-19 08:06:18 +02:00
..
binary_node.go trie/bintrie: unexport package-internal arena identifiers 2026-04-18 18:49:04 +02:00
binary_node_test.go trie/bintrie: unexport package-internal arena identifiers 2026-04-18 18:49:04 +02:00
hashed_node.go trie/bintrie: use type alias for HashedNode 2026-04-18 18:38:37 +02:00
hashed_node_test.go trie/bintrie: unexport package-internal arena identifiers 2026-04-18 18:49:04 +02:00
hasher.go trie/bintrie: revert sha256 helper + parallelHashDepth constant 2026-04-18 18:50:45 +02:00
internal_node.go trie/bintrie: unexport package-internal arena identifiers 2026-04-18 18:49:04 +02:00
internal_node_test.go trie/bintrie: unexport package-internal arena identifiers 2026-04-18 18:49:04 +02:00
iterator.go trie/bintrie: unexport package-internal arena identifiers 2026-04-18 18:49:04 +02:00
iterator_test.go trie/bintrie: unexport package-internal arena identifiers 2026-04-18 18:49:04 +02:00
key_encoding.go trie/bintrie: spec change, big endian hashing of slot key (#34670) 2026-04-13 09:42:37 +02:00
node_ref.go trie/bintrie: unexport package-internal arena identifiers 2026-04-18 18:49:04 +02:00
node_store.go trie/bintrie: trim storeChunkSize doc comment 2026-04-18 18:53:23 +02:00
stem_node.go trie/bintrie: keep StemNode.Hash's data array on stack 2026-04-19 08:06:18 +02:00
stem_node_test.go trie/bintrie: unexport package-internal arena identifiers 2026-04-18 18:49:04 +02:00
store_commit.go trie/bintrie: reuse path buffer in collectNodes 2026-04-19 08:00:33 +02:00
store_ops.go trie/bintrie: inline get/InsertValuesAtStem wrappers 2026-04-18 18:59:27 +02:00
trie.go trie/bintrie: reuse path buffer in collectNodes 2026-04-19 08:00:33 +02:00
trie_test.go trie/bintrie: add BenchmarkCollectNodesSparseWrite for allocation tracking 2026-04-18 19:12:55 +02:00