mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-14 02:41:34 +00:00
Gballet asked (comment 3099953085) to leave the sha256Sum256 / constant parallelHashDepth optimisation out of this PR: it's an orthogonal microbenchmark concern that should be revisited post-group-depth under Go 1.26. - Delete the sha256Sum256 helper from hasher.go. - Delete the const parallelHashDepth = 4 from hasher.go. - Restore master's dynamic parallelDepth() helper in store_commit.go (copy verbatim — min(bits.Len(NumCPU), 8)). - In hashInternal's shallow-parallel branch, call sha256.Sum256 directly (std-lib, stack-allocated [32]byte; common.Hash is a type alias for [32]byte so no conversion needed). - In hashInternal's deep-sequential branch, use the pooled newSha256 / returnSha256 hasher (matches master's internal_node.go:170-185). Intentional trade-off: the deep branch now re-introduces per-hash sync.Pool Get/Put plus a 32-byte h.Sum(nil) allocation. Zero regression vs master; foregoes the arena's proposed stack-based hashing until Go 1.26 + post-group-depth benchmarks.
39 lines
1 KiB
Go
39 lines
1 KiB
Go
// Copyright 2026 go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package bintrie
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"hash"
|
|
"sync"
|
|
)
|
|
|
|
var sha256Pool = sync.Pool{
|
|
New: func() any {
|
|
return sha256.New()
|
|
},
|
|
}
|
|
|
|
func newSha256() hash.Hash {
|
|
h := sha256Pool.Get().(hash.Hash)
|
|
h.Reset()
|
|
return h
|
|
}
|
|
|
|
func returnSha256(h hash.Hash) {
|
|
sha256Pool.Put(h)
|
|
}
|