Speed up use of PBKDF2 when building in Debug configuration #315
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
MongoKitten users (including those using the Fluent 4 driver built on it) sometimes experience significant connection delays during development due to the compiler not optimizing the PBKDF2 implementation. With a little help from Instruments, these delays can be massively reduced. The follow shows a timing comparison between the original code and that provided in this PR:
Comparisons
10,000 iterations of each hash are repeated 10x, and the total times averaged. Each test is run in Debug and Release configurations, against the original and revised implementations. The first number is the runtime average of the original code; the second number is the runtime average of the new code. The third number expresses how much of the original implementation's runtime is used by the revised one.
macOS (Xcode 15 beta 5)
5.736s / 0.256s (4.6%)
10.268s / 0.491s (4.8%)
13.799s / 0.483s (3.5%)
0.066s / 0.064s (97.0%)
0.099s / 0.089s (90.0%)
0.126s / 0.116s (92.1%)
Linux (swift:5.8-jammy)
1.711s / 0.297s (17.4%)
2.088s / 0.634s (30.2%)
3.135s / 0.631s (20.1%)
0.119s / 0.067s (56.3%)
0.083s / 0.082s (98.8%)
0.100s / 0.095s (95.0%)
Linux (5.9 nightly - swift-5.9-DEVELOPMENT-SNAPSHOT-2023-07-25-a)
1.379s / 0.290s (21.0%)
1.435s / 0.565s (39.4%)
1.625s / 0.715s (44.0%)
0.121s / 0.070s (57.9%)
0.083s / 0.085s (102%)
0.130s / 0.124s (95.4%)