-
Notifications
You must be signed in to change notification settings - Fork 20.9k
all: reuse the global hash buffer #31839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
I pretty deliberately not changed these cases as I think using the buffer here would be a tiny bit slower than reusing the buffer that we already have. I would be fine with merging it, if you could show that the two approaches are roughly the same time wise |
I added a benchmark test for $ go test -benchmem --benchtime=1m -run=^$ -bench ^BenchmarkSafeDeleteRange github.com/ethereum/go-ethereum/core/rawdb > old.txt
# change the code to reuse the hash pool
$ go test -benchmem --benchtime=1m -run=^$ -bench ^BenchmarkSafeDeleteRange github.com/ethereum/go-ethereum/core/rawdb > new.txt The diff as below: $ benchstat old.txt new.txt
goos: darwin
goarch: arm64
pkg: github.com/ethereum/go-ethereum/core/rawdb
cpu: Apple M4 Max
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
SafeDeleteRange-16 26.22m ± ∞ ¹ 23.07m ± ∞ ¹ ~ (p=1.000 n=1) ²
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05
│ old.txt │ new.txt │
│ B/op │ B/op vs base │
SafeDeleteRange-16 12.04Mi ± ∞ ¹ 11.23Mi ± ∞ ¹ ~ (p=1.000 n=1) ²
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05
│ old.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
SafeDeleteRange-16 119.9k ± ∞ ¹ 119.9k ± ∞ ¹ ~ (p=1.000 n=1) ²
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05
So I think the pool reuse performance should be a litter better than the old one? |
@MariusVanDerWijden looks like there is no big difference between two approaches. // goos: darwin
// goarch: arm64
// pkg: github.com/ethereum/go-ethereum/crypto
// cpu: Apple M1 Pro
// BenchmarkKeccak256Hash
// BenchmarkKeccak256Hash-8 931095 1270 ns/op 32 B/op 1 allocs/op
func BenchmarkKeccak256Hash(b *testing.B) {
var input [512]byte
rand.Read(input[:])
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Keccak256Hash(input[:])
}
}
// goos: darwin
// goarch: arm64
// pkg: github.com/ethereum/go-ethereum/crypto
// cpu: Apple M1 Pro
// BenchmarkHashData
// BenchmarkHashData-8 793386 1278 ns/op 32 B/op 1 allocs/op
func BenchmarkHashData(b *testing.B) {
var (
input [512]byte
buffer = NewKeccakState()
)
rand.Read(input[:])
b.ReportAllocs()
for i := 0; i < b.N; i++ {
HashData(buffer, input[:])
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
As #31769 defined a global hash pool, so we can reuse it, and also remove the unnecessary KeccakState buffering