Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 12 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ repository = "https://github.com/metrics-rs/metrics"
homepage = "https://github.com/metrics-rs/metrics"

[workspace.dependencies]
ahash = { version = "0.8", default-features = false }
aho-corasick = { version = "1", default-features = false }
approx = { version = "0.5", default-features = false }
base64 = { version = "0.22", default-features = false, features = ["std"] }
Expand Down Expand Up @@ -66,6 +65,7 @@ quickcheck_macros = { version = "1", default-features = false }
radix_trie = { version = "0.2", default-features = false }
rand = { version = "0.9", default-features = false, features = [ "thread_rng" ] }
rand_xoshiro = { version = "0.7", default-features = false }
rapidhash = { version = "4.1.1", default-features = false }
ratatui = { version = "0.29", default-features = false }
rustls = { version = "0.23", default-features = false }
sketches-ddsketch = { version = "0.3", default-features = false }
Expand Down
1 change: 0 additions & 1 deletion metrics-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ name = "bucket-crusher"
required-features = ["storage"]

[dependencies]
ahash = { workspace = true, optional = true }
aho-corasick = { workspace = true, features = ["std"], optional = true }
crossbeam-epoch = { workspace = true, features = ["alloc", "std"], optional = true }
crossbeam-utils = { workspace = true, optional = true }
Expand Down
2 changes: 1 addition & 1 deletion metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ name = "macros"
harness = false

[dependencies]
ahash = { workspace = true }
rapidhash = { workspace = true }

[target.'cfg(target_pointer_width = "32")'.dependencies]
portable-atomic = { version = "1", default-features = false, features = [
Expand Down
21 changes: 17 additions & 4 deletions metrics/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::hash::Hasher;

use ahash::AHasher;
use rapidhash::fast::RapidHasher;

use crate::cow::Cow;

Expand All @@ -19,12 +19,25 @@ pub type SharedString = Cow<'static, str>;

/// Key-specific hashing algorithm.
///
/// Currently uses AHash - <https://github.com/tkaitchuck/aHash>
/// Currently uses rapidhash - <https://github.com/hoxxep/rapidhash>
///
/// For any use-case within a `metrics`-owned or adjacent crate, where hashing of a key is required,
/// this is the hasher that will be used.
#[derive(Debug, Default)]
pub struct KeyHasher(AHasher);
pub struct KeyHasher(RapidHasher<'static>);

impl std::fmt::Debug for KeyHasher {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("KeyHasher").finish_non_exhaustive()
}
}

impl Default for KeyHasher {
fn default() -> Self {
// The seed should be randomized on application start if DoS resistance is required, but
// ahash was also previously using fixed seeds by default.
KeyHasher(RapidHasher::default_const())
}
}

impl Hasher for KeyHasher {
fn finish(&self) -> u64 {
Expand Down