RustCrypto / password-hashes

Password hashing functions / KDFs
652 stars 80 forks source link

[Curiosity] Speed difference debug/release argon2 #467

Closed kolbma closed 11 months ago

kolbma commented 11 months ago

Just a question of curiosity...

I've just stumbled over flamegraphs with argon2 password hashing.
My unit tests seems to be slow and the time (91%) is spent in Argon2::compress::compress_avx2 and Block::compress.
A single test in debug profile needs nearly a second to finish, while in release profile, it is a blink of an eye (ms area).

Are you aware of this difference?
Do you use always extra profile settings like the following to get acceptable runtimes of test harnesses?

[profile.dev.package.argon2]
opt-level = 3
debug = false
debug-assertions = false
overflow-checks = false
incremental = false
codegen-units = 16
tarcieri commented 11 months ago

Yes, we're aware.

All we do for our own development purposes is:

https://github.com/RustCrypto/password-hashes/blob/master/Cargo.toml#L14-L15

[profile.dev]
opt-level = 2

Cryptography generally tends towards computational complexity and the default opt-level is poorly suited for that, but turning it up just a little bit should add sufficient optimizations to eliminate your local development headache.