scrypt is extremely slow compared to native C bindings #1041
Unanswered
koraykoska
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I benchmarked CryptoSwift scrypt vs this library: https://github.com/greymass/swift-scrypt which is a C binding to libscrypt.
libscrypt scrypt seems to be 4 times faster than CryptoSwift scrypt.
Both have been release compiled with optimizations.
After time profiling I found out which code segments are the issue:
This function takes up about 90% of the total time:
https://github.com/krzyzanowskim/CryptoSwift/blob/main/Sources/CryptoSwift/Scrypt.swift#L206
More specifically, this
rotateLeft
uses up again more than 90% of thesalsa20_8_typed
function:https://github.com/krzyzanowskim/CryptoSwift/blob/main/Sources/CryptoSwift/Utils.swift#L18
The fun bit is that the 1 line of code in
rotateLeft
is basically exactly the same in the C code in libscrypt.Has anyone an idea what's causing this slowdown? It's actually so slow that even the JS implementation is faster. Something is up with it but I don't know what it is. Right now it's not usable in production.
Beta Was this translation helpful? Give feedback.
All reactions