Skip to content

Commit df814d7

Browse files
committed
sha256: drop minio in favor of crypto/sha256 for go1.21 and above
In go1.21 the go std has a new SHANI accelerated rountine (just like minio's sha256). See golang/go#50543. Reduce the code surface by dropping what is now a redondent librairy. Benchmarks using go1.21 and go1.20 shows no significant difference between minio and the std for sha256: ``` name old time/op new time/op delta SumAllLarge/sha2-256-12 8.63ms ± 3% 8.63ms ± 1% ~ (p=0.220 n=20+17) SumAllLarge/sha2-512-12 23.1ms ± 3% 23.0ms ± 3% ~ (p=0.361 n=18+20) SumAllLarge/dbl-sha2-256-12 36.0ms ± 4% 8.6ms ± 4% -76.16% (p=0.000 n=20+20) name old speed new speed delta SumAllLarge/sha2-256-12 1.94GB/s ± 4% 1.95GB/s ± 1% ~ (p=0.220 n=20+17) SumAllLarge/sha2-512-12 725MB/s ± 3% 729MB/s ± 3% ~ (p=0.350 n=18+20) SumAllLarge/dbl-sha2-256-12 467MB/s ± 4% 1958MB/s ± 4% +319.53% (p=0.000 n=20+20) ``` `dlb-sha2-256` doubled in speed because it was never wired to use minio's sha256 implementation and thus was bumped by `crypto/sha256`'s improvement. I think we should remove `github.com/multiformats/go-multihash/register/miniosha256` one go1.22 is released (~1 year) since it would be purposeless, we could also stub it to github.com/multiformats/go-multihash/register/sha256 for all versions but [no one imports it directly](https://pkg.go.dev/github.com/multiformats/go-multihash/register/miniosha256?tab=importedby).
1 parent 608669d commit df814d7

File tree

4 files changed

+72
-23
lines changed

4 files changed

+72
-23
lines changed

register/miniosha256/multihash_miniosha256.go

Lines changed: 0 additions & 23 deletions
This file was deleted.

register/miniosha256/post_go1.21.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//go:build go1.21
2+
3+
// This package has no purpose except to perform registration of multihashes.
4+
//
5+
// It is meant to be used as a side-effecting import, e.g.
6+
//
7+
// import (
8+
// _ "github.com/multiformats/go-multihash/register/miniosha256"
9+
// )
10+
//
11+
// This package registers alternative implementations for sha2-256, using
12+
// the github.com/minio/sha256-simd library for go1.20 and bellow. Go 1.21 and
13+
// later fallback to [github.com/multiformats/go-multihash/register/sha256].
14+
//
15+
// Deprecated: please switch to [github.com/multiformats/go-multihash/register/sha256]
16+
// as of go1.21 the go std has a SHANI implementation that is just as fast. See https://go.dev/issue/50543.
17+
// This will be removed shortly after go1.22 is released.
18+
package miniosha256
19+
20+
import (
21+
_ "github.com/multiformats/go-multihash/register/sha256"
22+
)

register/miniosha256/pre_go1_21.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//go:build !go1.21
2+
3+
// This package has no purpose except to perform registration of multihashes.
4+
//
5+
// It is meant to be used as a side-effecting import, e.g.
6+
//
7+
// import (
8+
// _ "github.com/multiformats/go-multihash/register/miniosha256"
9+
// )
10+
//
11+
// This package registers alternative implementations for sha2-256, using
12+
// the github.com/minio/sha256-simd library for go1.20 and bellow. Go 1.21 and
13+
// later fallback to [github.com/multiformats/go-multihash/register/sha256].
14+
//
15+
// Note if you are using go1.21 or above this package is deprecated in favor of
16+
// [github.com/multiformats/go-multihash/register/sha256] because as of go1.21
17+
// the go std has a SHANI implementation that is just as fast. See https://go.dev/issue/50543.
18+
// This will be removed shortly after go1.22 is released.
19+
package miniosha256
20+
21+
import (
22+
"github.com/minio/sha256-simd"
23+
24+
"github.com/multiformats/go-multihash/core"
25+
)
26+
27+
func init() {
28+
multihash.Register(multihash.SHA2_256, sha256.New)
29+
}

register/sha256/sha256.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This package has no purpose except to perform registration of multihashes.
2+
//
3+
// It is meant to be used as a side-effecting import, e.g.
4+
//
5+
// import (
6+
// _ "github.com/multiformats/go-multihash/register/sha256"
7+
// )
8+
//
9+
// This package registers an implementation of sha256 using the go std, this is
10+
// recomanded if you are using go1.21 or above.
11+
package sha256
12+
13+
import (
14+
"crypto/sha256"
15+
16+
"github.com/multiformats/go-multihash/core"
17+
)
18+
19+
func init() {
20+
multihash.Register(multihash.SHA2_256, sha256.New)
21+
}

0 commit comments

Comments
 (0)