Skip to content

Conversation

@AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented Nov 29, 2022

https://github.com/minio/sha256-simd simdizes sha256 computation on amd64 and arm64.

Micro benchmark: ctr images pull docker.io/library/fedora:latest on Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz (with sha_ni), 4 cores

Before:

9.110s
9.172s
9.390s

After:

8.609s
8.321s
8.654s

@dmcgowan
Copy link
Member

Hopefully this is could be a temporary change and Go can find an upstream solution. The performance improvement is significant enough to pull in though.

@thaJeztah
Copy link
Member

Hopefully this is could be a temporary change and Go can find an upstream solution. The performance improvement is significant enough to pull in though.

Looks like it was merged in Go master; golang/go#53084 - see golang/go@f1b1557 (not sure if more is needed after that>), which would mean this will be in go1.20?

If so, should we add a TODO comment to remove it after we switched to go1.20?

@AkihiroSuda AkihiroSuda marked this pull request as draft November 30, 2022 03:43
@AkihiroSuda
Copy link
Member Author

Looks like it was merged in Go master; golang/go#53084 - see golang/go@f1b1557 (not sure if more is needed after that>), which would mean this will be in go1.20?

crypto/sha256: add sha-ni implementation ( https://go-review.googlesource.com/c/go/+/408795/1 ) doesn't seem merged.
Not sure it will be merged before Go 1.20.

@AkihiroSuda AkihiroSuda marked this pull request as ready for review November 30, 2022 12:36
@AkihiroSuda
Copy link
Member Author

Added a code comment

func NewSHA256() hash.Hash {
        // An equivalent of sha256-simd is expected to be merged in Go 1.20 (1.21?): https://go-review.googlesource.com/c/go/+/408795/1
        return sha256simd.New()
}

@estesp
Copy link
Member

estesp commented Dec 1, 2022

Strange that github claims there are conflicts but doesn't list any file conflicts?

@crazy-max
Copy link
Contributor

@AkihiroSuda Would it be relevant to have this new computation in BuildKit too?

@AkihiroSuda
Copy link
Member Author

@AkihiroSuda Would it be relevant to have this new computation in BuildKit too?

Yes, I guess we can safely have this in BuildKit (and Moby, etc.)

@cpuguy83
Copy link
Member

cpuguy83 commented Dec 1, 2022

This is pretty cool, but I wonder if this should be opt-in given that the performance advantage is fairly negligible unless you are doing a lot digesting vs the breadth of code that relies on sha256.
This could even be a plugin that is disabled by default where the plugin init would register the hasher.

@AkihiroSuda
Copy link
Member Author

opt-in

Any drawback to enable SIMD by default?

This could even be a plugin that is disabled by default where the plugin init would register the hasher.

I'm not sure. The plugin will be NOP when https://go-review.googlesource.com/c/go/+/408795/1 is merged.

@samuelkarp
Copy link
Member

This is pretty cool, but I wonder if this should be opt-in given that the performance advantage is fairly negligible unless you are doing a lot digesting vs the breadth of code that relies on sha256.

Are you concerned mostly with bugs in this implementation or reliability of the CPU instructions or something else?

This could even be a plugin that is disabled by default where the plugin init would register the hasher.

Another alternative would be to make this a build tag. Then there wouldn't be an extra plugin hanging around if this gets folded into Go.

@kzys
Copy link
Member

kzys commented Dec 7, 2022

Does the Go upstream have aarch64 support already? If not, sha256-simd would cover more architectures than the upstream change.

@AkihiroSuda
Copy link
Member Author

Copy link
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Edit for correction: Given it appears the Go core library will be adopting this a hardware-accelerated implementation of sha256, seems reasonable for us to move here as we're only doing it for the 1.7 line, which will end up on Go 1.20/1.21+ not that long into the support cycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

9 participants