Suggestion: use rapidhash for KeyHasher #651
Open
+31
−49
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.
Disclosure: I am the author of rapidhash.
Hey! This PR is a suggestion to replace the use of ahash with rapidhash. Rapidhash has been used in production workloads for the last year and outperforms ahash on almost all inputs and platforms.
This makes a significant improvement on the following benchmarks:
The improvements were benchmarked on an M1 Max with and without
-C target-cpu=native. The rapidhash detailed benchmarks suggest rapidhash outperforms the ahash primary (with AES instructions) and fallback (without AES instructions) algorithms on almost all inputs on almost all platforms (1kB+ strings on x86 with AES enabled being a notable exception). I'm happy to talk through the benchmarks in more detail if that's helpful.Note that metrics does not randomly seed the KeyHasher, and so the hashes are not DoS resistant in neither the old ahash implementation nor this PR. Let me know if this is a concern and I can adjust this PR to use rapidhash's
GlobalStateto provide some DoS resistance.The rapidhash MSRV is 1.71.0, which should be enough for the current metrics MSRV.
Let me know if you have further questions about rapidhash, or would like me to assist in further benchmarking? Cheers!