From 82f07fe6d1ee294bae43f311bf8a400e24c2f95f Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 17 Feb 2025 17:28:57 -0500 Subject: [PATCH] Migrate helix-event to foldhash This is following `hashbrown`'s switch in v0.15 from ahash to foldhash for its `default-haster` feature, applied only to helix-event for now. I don't have a strong preference between the two. Benchmarks in Spellbook, which is particularly sensitive to hashers and hash table performance, show no perceptible difference. Foldhash is dependency-free though. Once we migrate to the new tree-sitter bindings and highlighter we should be able to eliminate the remaining dependencies on ahash. --- Cargo.lock | 6 ++++-- Cargo.toml | 1 + helix-event/Cargo.toml | 4 ++-- helix-event/src/registry.rs | 8 ++++---- helix-event/src/runtime.rs | 7 ++++--- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1fb1685..c6b2efa1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1310,6 +1310,8 @@ version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" dependencies = [ + "allocator-api2", + "equivalent", "foldhash", ] @@ -1371,10 +1373,10 @@ dependencies = [ name = "helix-event" version = "25.1.1" dependencies = [ - "ahash", "anyhow", + "foldhash", "futures-executor", - "hashbrown 0.14.5", + "hashbrown 0.15.2", "log", "once_cell", "parking_lot", diff --git a/Cargo.toml b/Cargo.toml index 56234a86..ab0f8b48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ tempfile = "3.16.0" bitflags = "2.8" unicode-segmentation = "1.2" ropey = { version = "1.6.1", default-features = false, features = ["simd"] } +foldhash = "0.1" [workspace.package] version = "25.1.1" diff --git a/helix-event/Cargo.toml b/helix-event/Cargo.toml index ee4038e6..c6ab11c6 100644 --- a/helix-event/Cargo.toml +++ b/helix-event/Cargo.toml @@ -12,8 +12,8 @@ homepage.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ahash = "0.8.11" -hashbrown = "0.14.5" +foldhash.workspace = true +hashbrown = "0.15" tokio = { version = "1", features = ["rt", "rt-multi-thread", "time", "sync", "parking_lot", "macros"] } # the event registry is essentially read only but must be an rwlock so we can # setup new events on initialization, hardware-lock-elision hugely benefits this case diff --git a/helix-event/src/registry.rs b/helix-event/src/registry.rs index d43c48ac..551d7014 100644 --- a/helix-event/src/registry.rs +++ b/helix-event/src/registry.rs @@ -14,8 +14,8 @@ use crate::hook::ErasedHook; use crate::runtime_local; pub struct Registry { - events: HashMap<&'static str, TypeId, ahash::RandomState>, - handlers: HashMap<&'static str, Vec, ahash::RandomState>, + events: HashMap<&'static str, TypeId, foldhash::fast::FixedState>, + handlers: HashMap<&'static str, Vec, foldhash::fast::FixedState>, } impl Registry { @@ -105,8 +105,8 @@ runtime_local! { static REGISTRY: RwLock = RwLock::new(Registry { // hardcoded random number is good enough here we don't care about DOS resistance // and avoids the additional complexity of `Option` - events: HashMap::with_hasher(ahash::RandomState::with_seeds(423, 9978, 38322, 3280080)), - handlers: HashMap::with_hasher(ahash::RandomState::with_seeds(423, 99078, 382322, 3282938)), + events: HashMap::with_hasher(foldhash::fast::FixedState::with_seed(72536814787)), + handlers: HashMap::with_hasher(foldhash::fast::FixedState::with_seed(72536814787)), }); } diff --git a/helix-event/src/runtime.rs b/helix-event/src/runtime.rs index 8da465ef..02d66fb6 100644 --- a/helix-event/src/runtime.rs +++ b/helix-event/src/runtime.rs @@ -41,8 +41,9 @@ macro_rules! runtime_local { #[cfg(feature = "integration_test")] pub struct RuntimeLocal { - data: - parking_lot::RwLock>, + data: parking_lot::RwLock< + hashbrown::HashMap, + >, init: fn() -> T, } @@ -53,7 +54,7 @@ impl RuntimeLocal { pub const fn __new(init: fn() -> T) -> Self { Self { data: parking_lot::RwLock::new(hashbrown::HashMap::with_hasher( - ahash::RandomState::with_seeds(423, 9978, 38322, 3280080), + foldhash::fast::FixedState::with_seed(12345678910), )), init, }