From d20aff012dff09b4edb2cc6955e9038ae057df3d Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 4 Nov 2025 14:12:26 +0100 Subject: [PATCH] perf: use IdentityMap --- Cargo.lock | 13 ++++++++++--- quinn-proto/Cargo.toml | 1 + quinn-proto/src/connection/paths.rs | 10 +++++++++- quinn-proto/src/connection/timer.rs | 6 +++--- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c12129d92..7e794a9fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -744,7 +744,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.61.1", ] [[package]] @@ -1028,6 +1028,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "identity-hash" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfdd7caa900436d8f13b2346fe10257e0c05c1f1f9e351f4f5d57c03bd5f45da" + [[package]] name = "idna" version = "1.1.0" @@ -1117,6 +1123,7 @@ dependencies = [ "fastbloom", "getrandom 0.3.3", "hex-literal", + "identity-hash", "lazy_static", "lru-slab", "qlog", @@ -1705,7 +1712,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.61.1", ] [[package]] @@ -2447,7 +2454,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.61.1", ] [[package]] diff --git a/quinn-proto/Cargo.toml b/quinn-proto/Cargo.toml index 1c34fdbc9..0494ce898 100644 --- a/quinn-proto/Cargo.toml +++ b/quinn-proto/Cargo.toml @@ -52,6 +52,7 @@ slab = { workspace = true } thiserror = { workspace = true } tinyvec = { workspace = true, features = ["alloc"] } tracing = { workspace = true } +identity-hash = "0.1.0" # Feature flags & dependencies for wasm # wasm-bindgen is assumed for a wasm*-*-unknown target diff --git a/quinn-proto/src/connection/paths.rs b/quinn-proto/src/connection/paths.rs index 0047e2ee9..cd9083582 100644 --- a/quinn-proto/src/connection/paths.rs +++ b/quinn-proto/src/connection/paths.rs @@ -18,9 +18,17 @@ use crate::{ use qlog::events::quic::MetricsUpdated; /// Id representing different paths when using multipath extension -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)] pub struct PathId(pub(crate) u32); +impl std::hash::Hash for PathId { + fn hash(&self, state: &mut H) { + state.write_u32(self.0); + } +} + +impl identity_hash::IdentityHashable for PathId {} + impl coding::Codec for PathId { fn decode(r: &mut B) -> coding::Result { let v = VarInt::decode(r)?; diff --git a/quinn-proto/src/connection/timer.rs b/quinn-proto/src/connection/timer.rs index a835e4e70..82c842a58 100644 --- a/quinn-proto/src/connection/timer.rs +++ b/quinn-proto/src/connection/timer.rs @@ -1,4 +1,4 @@ -use rustc_hash::FxHashMap; +use identity_hash::{IdentityHashable, IntMap}; use crate::Instant; @@ -86,7 +86,7 @@ const STACK_TIMERS: usize = 4; #[derive(Debug, Clone)] struct SmallMap { stack: [Option<(K, V)>; SIZE], - heap: Option>, + heap: Option>, } impl Default for SmallMap { @@ -100,7 +100,7 @@ impl Default for SmallMap { impl SmallMap where - K: std::cmp::Eq + std::hash::Hash, + K: std::cmp::Eq + std::hash::Hash + IdentityHashable, { fn insert(&mut self, key: K, value: V) -> Option { // check stack for space