Skip to content
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

Performance on Apple Silicon #601

Closed
brookman opened this issue Apr 19, 2024 · 5 comments
Closed

Performance on Apple Silicon #601

brookman opened this issue Apr 19, 2024 · 5 comments

Comments

@brookman
Copy link

Hi. Thanks for providing the awesome crypto crates! 🦀
I was experimenting with the ChaCha20Poly1305 crate and found it to run 4x slower on a Mac with M1 CPU compared to an older Intel i7 Mac. Now I‘m wondering if this is a general issue with Rust (it seems that the arm64/AArch64-Apple-Darwin target is not tier 1 yet) or if there are specific optimizations in the RustCrypto crates for Intel. Or maybe I‘m missing a feature flag? Could somebody give me a hint here?

Thanks in advance!

@brookman brookman changed the title Performance on Apple Silicone Performance on Apple Silicon Apr 19, 2024
@tarcieri
Copy link
Member

tarcieri commented Apr 23, 2024

The chacha20 and poly1305 crates have AVX2-optimized implementations on Intel. On ARM64 we use a portable software implementation instead and have no SIMD support for these crates on ARM64 platforms other than what LLVM's auto-vectorization might be doing.

The aes-gcm crate, on the other hand, supports ARMv8 hardware acceleration for AES and GCM (i.e. PMULL) and will get you better results on M1.

@tripplet
Copy link

tripplet commented Apr 24, 2024

There is a neon/aarch64 backend for the underlying RustCrypto/stream-ciphers/chacha20 which is supported on modern Apple arm processors but it must be enabled explicitly
chacha20/README.md
chacha20/src/backends.rs#L18

@brookman
Copy link
Author

Thank you for the hint @tripplet !
I'm trying to enable it by adding the following to my .cargo/config.toml file:

[target.aarch64-linux-android]
rustflags = ["-C", "target-feature=+neon", "--cfg", "chacha20_force_neon"]

[target.aarch64-apple-ios]
rustflags = ["-C", "target-feature=+neon", "--cfg", "chacha20_force_neon"]

[target.aarch64-apple-darwin]
rustflags = ["-C", "target-feature=+neon", "--cfg", "chacha20_force_neon"]

Am I doing this correctly?

@tripplet
Copy link

tripplet commented Apr 24, 2024

I'm not experienced in cross compilation, I only used rustflags = ["--cfg", "chacha20_force_neon"] to compile on Mac for Mac but looks good to me.

@brookman
Copy link
Author

@tripplet it works. Thank you very much! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants