-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
crypto/sha256: Sum256 performance regression in Go 1.24 #71943
Comments
Related Issues
Related Code Changes
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
cc @FiloSottile |
That's surprising, we have a test to make sure there is no allocation in that path. Maybe it's broken because it doesn't use the output? Will try to reproduce. https://cs.opensource.google/go/go/+/refs/tags/go1.24.0:src/crypto/sha256/sha256_test.go;l=298-322 |
Also note that it does string concatenation |
On gotip: func BenchmarkVerify(b *testing.B) {
for b.Loop() {
f := make([]byte, 32)
rand.Read(f)
runtime.KeepAlive(Sum256(f))
}
} func BenchmarkVerify(b *testing.B) {
for b.Loop() {
runtime.KeepAlive(Sum256([]byte("teststring" + "test")))
}
} both of these (above) do not allocate, but following (below) cases allocate: func BenchmarkVerify(b *testing.B) {
for b.Loop() {
runtime.KeepAlive(Verify("teststring", "test"))
}
}
func Verify(token, salt string) [32]byte {
return Sum256([]byte(token + salt))
} func BenchmarkVerify(b *testing.B) {
for b.Loop() {
str := "teststring"
runtime.KeepAlive(Sum256([]byte(str + "test")))
}
} In these cases the 32 Byte optimization is unused. CC @golang/compiler |
Probably caused by CL 527935, before these changes go/src/cmd/compile/internal/walk/expr.go Lines 479 to 503 in f69703d
|
Oh interesting, thank you all for looking into this. Can indeed confirm that the following fixes the regression: func Verify(token, salt string) {
- sha256.Sum256([]byte(salt + token))
+ input := salt + token
+ sha256.Sum256([]byte(input))
} |
Change https://go.dev/cl/652395 mentions this issue: |
After upgrading from Go
1.23.4
to1.24
our regression test started to fail for a function where we compute the SHA256 checksum for a token + salt.Reproduction
I can reproduce this with:
Benchmark results
Go
1.23.4
Go
1.24
Potential cause
I see the implementation changed between versions:
But is the performance regression expected?
The release notes only mention the new interface implementation for
crypto/sha256
.And from what I understand, the fips140/sha256 is disabled by default?
The text was updated successfully, but these errors were encountered: