Replies: 11 comments
-
Do you test Release build? I didn't notice this regression in performance tests hm. |
Beta Was this translation helpful? Give feedback.
-
Yes, I tried different release builds. |
Beta Was this translation helpful? Give feedback.
-
Same here! Version 1.0.0 is way faster than 1.3.2. |
Beta Was this translation helpful? Give feedback.
-
do you use swift 5.3 on CryptoSwift 1.0? I'm yet to diagnose whether it's compiler or swift code regression |
Beta Was this translation helpful? Give feedback.
-
Yes, I use swift 5.3. |
Beta Was this translation helpful? Give feedback.
-
This makes me think and I run test SHA1 SHA256 SHA512 When I run 2048 iterations, as per @sche example, the result is Although there's a difference that is visible in numbers, it's not what I expected to see. If it takes you more than a second, that cany only means you're running unoptimized Swift (aka debug build). What I'm missing here? My mac is 2,8 GHz Quad-Core Intel Core i7 |
Beta Was this translation helpful? Give feedback.
-
Hi @krzyzanowskim ,
It works slow on optimized Swift for me when it is improted as a dependency. But only with versions > 1.0 Could you try to run the same performance test in a setup I described? (importing CryptoSwift with CocoaPods / SwiftPM) |
Beta Was this translation helpful? Give feedback.
-
What is your Podfile, is this master branch or 1.3.2? what Xcode and CocoaPods version. Does Pod target uses Release for sure? There are so many configuration nuances with Cocoapods
I created SwiftPM sample package with your test code https://github.com/krzyzanowskim/CryptoSwift/issues/832#issue-716527818
And the same but with Xcode Duration: 0.020154953002929688 (seconds)Can you run it and report back result? |
Beta Was this translation helpful? Give feedback.
-
I checked out CryptoSwift master branch, opened CryptoSwift.xcodeproj and tried to run PBKDFPerf tests. Your example on my mac:
Here I tried to run same test in iOS app on iPhone 11 (14.1) simulator with CryptoSwift 1.3.2:
But now it is slow even if I try to run it with 1.0.0 version imported via SwiftPM 🤷♂️
But it works if I change version to 1.3.2 (which is still slow) |
Beta Was this translation helpful? Give feedback.
-
simulator speed is pretty much your mac speed, are you sure you didn't run debug build there?
some cocoapods setup leftovers gets in the way, either re-setup cocoapods, delete pods caches, derived data etc. happens with Xcode quite a lot. |
Beta Was this translation helpful? Give feedback.
-
Starting v1.3.4 I distribute pre-compiled release version of the framework for Apple platforms. https://github.com/krzyzanowskim/CryptoSwift/issues/833#issuecomment-727293595 |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
After v1.0.0 the
PKCS5.PBKDF2
works much slower. It influences crypto-projects that rely on CryptoSwift.E.g.
HDWallet: https://github.com/essentiaone/HDWallet/blob/c1c5beb470d52673b89388b09d782345609d78f2/HDWalletKit/Mnemonic/Mnemonic.swift#L51
web3swift: https://github.com/matter-labs/web3swift/blob/e36e767eb2de26decb0c157aeef2d023a1175076/Sources/web3swift/KeystoreManager/BIP39.swift#L152
Both libraries rely at the moment on CryptoSwift v1.0.0
Because of this, provided places in libs generate mnemonic seed several seconds with CryptoSwift v > 1.0.0
I tried to dig into to understand what causes it, and the bottleneck is here:
CryptoSwift/Sources/CryptoSwift/SHA2.swift
Line 184 in af1b58f
Benchmarking this loop in v1.0.0 compared to v1.2.0 demonstrates that in v1.0.0 it works much faster.
Here is a unit test to check it:
Results for v1.0.0 on my mac with 2,4 GHz 8-Core Intel Core i9:
Start: 2020-10-07 13:11:01 +0000
End: 2020-10-07 13:11:01 +0000
Results for v1.2.0
Start: 2020-10-07 13:16:27 +0000
End: 2020-10-07 13:16:32 +0000
I tied to replace in 1.2.0 completely files
SHA2.swift
andUtils.swift
with version from 1.0.0 but it did not help.Probably this is an already known issue.
Beta Was this translation helpful? Give feedback.
All reactions