Skip to content

Conversation

@hoxxep
Copy link

@hoxxep hoxxep commented Dec 9, 2025

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:

  • macros/global_initialized/with_dynamic_labels (-30%)
  • macros/local_initialized/with_dynamic_labels (-30%)
  • registry/uncached op (basic) (-19%)
  • registry/uncached op (labels) (-29%)
  • registry/const key data overhead (labels) (-4%)
  • registry/owned key overhead (basic) (-45%)
  • registry/owned key overhead (labels) (-37%)

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 is currently not randomly seeding the KeyHasher, and so the hashes are not DoS resistant. Let me know if this is a concern and I can adjust the PR?

The rapidhash MSRV is 1.71.0, which should match the current metrics MSRV too.

Let me know if you have further questions about rapidhash, or would like me to assist in further benchmarking? Cheers!

@hoxxep hoxxep changed the title Use rapidhash for KeyHasher Suggestion: use rapidhash for KeyHasher Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant