-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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/cipher: optimize safeXORBytes #35381
Comments
(Aside: I've wanted encoding/binary.NativeEndian to exist on multiple occasions. Here's another one.) |
Will give this a shot on the weekend. |
I agree this would be very useful. Some discussion in the past: https://groups.google.com/forum/#!topic/golang-nuts/3GEzwKfRRQw |
Awesome. No rush, in any case—the freeze just started, so nothing will go in for three months. Thanks for the pointer to previous discussion of native endianness. I’ll file a proposal to discuss. |
If you implement a generic, fast (See CL 203837.) CC @FiloSottile |
Proposal at #35398. |
Added in nhooyr@24ce00e Results against xorBytesSSE2 on amd64:
So safe fast is still about 2x as slow. Still 10x faster in my testing than basic simple xor though. |
Added safe xor to the benchmark:
Sometimes nearly 3x as slow as the current default. |
cc @FiloSottile for removing assembly in favor of pure Go Filippo, is 2x-3x in this case within range of switching to pure Go? There may also be further optimizations available (either in the pure Go or in the compiler); I haven't checked yet, and may not for a little while. cc @CAFxX who I believe likes optimizing stuff like this |
Optimize safeXORBytes based on this conversation: golang#35381
Optimize safeXORBytes based on this conversation: golang#35381
Hello all! I gave this optimization a shot in the PR above. First time contributing to golang so looking for all kinds of feedback 🙇 |
Optimize safeXORBytes based on this conversation: golang#35381
Optimize safeXORBytes based on this conversation: golang#35381
The discussion at #31586 includes several techniques for optimizing xor of byte slices, including using encoding/binary (with native endianness) and loop unrolling. It'd be nice to apply them to
safeXORBytes
, which is used on many non-amd64 platforms. An optimizedsafeXORBytes
might even be fast enough that we could deletefastXORBytes
.Somewhat related: #30553
cc @nhooyr
The text was updated successfully, but these errors were encountered: