diff --git a/Cargo.lock b/Cargo.lock index d0a3ced923..633320b36d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -828,6 +828,7 @@ dependencies = [ "qlog", "quinn-udp", "regex", + "rustc-hash", "tokio", "url", ] @@ -879,6 +880,7 @@ dependencies = [ "neqo-qpack", "neqo-transport", "qlog", + "rustc-hash", "sfv", "test-fixture", "url", @@ -892,6 +894,7 @@ dependencies = [ "neqo-common", "neqo-transport", "qlog", + "rustc-hash", "static_assertions", "test-fixture", ] @@ -910,6 +913,7 @@ dependencies = [ "neqo-crypto", "neqo-transport", "qlog", + "rustc-hash", "smallvec", "static_assertions", "strum", diff --git a/Cargo.toml b/Cargo.toml index 016b27f67a..9382aaabd6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ log = { version = "0.4", default-features = false } qlog = { version = "0.13", default-features = false } quinn-udp = { version = "0.5.10", default-features = false, features = ["direct-log", "fast-apple-datapath"] } regex = { version = "1.9", default-features = false } +rustc-hash = { version = "1.1", default-features = false, features = [ "std" ]} static_assertions = { version = "1.1", default-features = false } strum = { version = "0.26", default-features = false, features = ["derive"] } url = { version = "2.5", default-features = false, features = ["std"] } diff --git a/neqo-bin/Cargo.toml b/neqo-bin/Cargo.toml index ac2e9e581a..cca6694b2f 100644 --- a/neqo-bin/Cargo.toml +++ b/neqo-bin/Cargo.toml @@ -39,6 +39,7 @@ neqo-udp = { path = "./../neqo-udp" } qlog = { workspace = true } quinn-udp = { workspace = true } regex = { workspace = true, features = ["unicode-perl"] } +rustc-hash = { workspace = true } tokio = { version = "1", default-features = false, features = ["net", "time", "macros", "rt", "rt-multi-thread"] } url = { workspace = true } diff --git a/neqo-bin/src/client/http09.rs b/neqo-bin/src/client/http09.rs index 0fc600765b..d6bcdcd9e7 100644 --- a/neqo-bin/src/client/http09.rs +++ b/neqo-bin/src/client/http09.rs @@ -10,7 +10,7 @@ use std::{ cell::RefCell, - collections::{HashMap, VecDeque}, + collections::VecDeque, fs::File, io::{BufWriter, Write as _}, net::SocketAddr, @@ -25,6 +25,7 @@ use neqo_transport::{ CloseReason, Connection, ConnectionEvent, ConnectionIdGenerator, EmptyConnectionIdGenerator, Error, Output, RandomConnectionIdGenerator, State, StreamId, StreamType, }; +use rustc_hash::FxHashMap as HashMap; use url::Url; use super::{get_output_file, qlog_new, Args, CloseState, Res}; @@ -226,7 +227,7 @@ impl super::Client for Connection { impl<'b> Handler<'b> { pub fn new(url_queue: VecDeque, args: &'b Args) -> Self { Self { - streams: HashMap::new(), + streams: HashMap::default(), url_queue, handled_urls: Vec::new(), all_paths: Vec::new(), diff --git a/neqo-bin/src/client/http3.rs b/neqo-bin/src/client/http3.rs index 6e8e25c4d5..ad718e963a 100644 --- a/neqo-bin/src/client/http3.rs +++ b/neqo-bin/src/client/http3.rs @@ -10,7 +10,7 @@ use std::{ cell::RefCell, - collections::{HashMap, VecDeque}, + collections::VecDeque, fmt::Display, fs::File, io::{BufWriter, Write as _}, @@ -27,6 +27,7 @@ use neqo_transport::{ AppError, CloseReason, Connection, EmptyConnectionIdGenerator, Error as TransportError, Output, RandomConnectionIdGenerator, StreamId, }; +use rustc_hash::FxHashMap as HashMap; use url::Url; use super::{get_output_file, qlog_new, Args, CloseState, Res}; @@ -45,7 +46,7 @@ impl<'a> Handler<'a> { let url_handler = UrlHandler { url_queue, handled_urls: Vec::new(), - stream_handlers: HashMap::new(), + stream_handlers: HashMap::default(), all_paths: Vec::new(), args, }; diff --git a/neqo-bin/src/client/mod.rs b/neqo-bin/src/client/mod.rs index fe2b6b9003..f8f39c06db 100644 --- a/neqo-bin/src/client/mod.rs +++ b/neqo-bin/src/client/mod.rs @@ -7,7 +7,7 @@ #![expect(clippy::unwrap_used, reason = "This is example code.")] use std::{ - collections::{HashMap, VecDeque}, + collections::VecDeque, fmt::{self, Display}, fs::{create_dir_all, File, OpenOptions}, io::{self, BufWriter}, @@ -31,6 +31,7 @@ use neqo_crypto::{ use neqo_http3::Output; use neqo_transport::{AppError, CloseReason, ConnectionId, Version}; use neqo_udp::RecvBuf; +use rustc_hash::FxHashMap as HashMap; use tokio::time::Sleep; use url::{Host, Origin, Url}; @@ -528,10 +529,13 @@ const fn local_addr_for(remote_addr: &SocketAddr, local_port: u16) -> SocketAddr fn urls_by_origin(urls: &[Url]) -> impl Iterator)> { urls.iter() - .fold(HashMap::>::new(), |mut urls, url| { - urls.entry(url.origin()).or_default().push_back(url.clone()); - urls - }) + .fold( + HashMap::>::default(), + |mut urls, url| { + urls.entry(url.origin()).or_default().push_back(url.clone()); + urls + }, + ) .into_iter() .filter_map(|(origin, urls)| match origin { Origin::Tuple(_scheme, h, p) => Some(((h, p), urls)), diff --git a/neqo-bin/src/server/http09.rs b/neqo-bin/src/server/http09.rs index 72b95adb17..bd4b8b8a0e 100644 --- a/neqo-bin/src/server/http09.rs +++ b/neqo-bin/src/server/http09.rs @@ -6,7 +6,7 @@ #![expect(clippy::unwrap_used, reason = "This is example code.")] -use std::{borrow::Cow, cell::RefCell, collections::HashMap, fmt::Display, rc::Rc, time::Instant}; +use std::{borrow::Cow, cell::RefCell, fmt::Display, rc::Rc, time::Instant}; use neqo_common::{event::Provider as _, hex, qdebug, qerror, qinfo, qwarn, Datagram}; use neqo_crypto::{generate_ech_keys, random, AllowZeroRtt, AntiReplay}; @@ -16,6 +16,7 @@ use neqo_transport::{ ConnectionEvent, ConnectionIdGenerator, Output, State, StreamId, }; use regex::Regex; +use rustc_hash::FxHashMap as HashMap; use super::{qns_read_response, Args}; use crate::{send_data::SendData, STREAM_IO_BUFFER_SIZE}; @@ -68,8 +69,8 @@ impl HttpServer { let is_qns_test = args.shared.qns_test.is_some(); Ok(Self { server, - write_state: HashMap::new(), - read_state: HashMap::new(), + write_state: HashMap::default(), + read_state: HashMap::default(), is_qns_test, regex: if is_qns_test { Regex::new(r"GET +/(\S+)(?:\r)?\n").map_err(|_| Error::Internal)? diff --git a/neqo-bin/src/server/http3.rs b/neqo-bin/src/server/http3.rs index 13f07706e0..2cbb315577 100644 --- a/neqo-bin/src/server/http3.rs +++ b/neqo-bin/src/server/http3.rs @@ -8,7 +8,6 @@ use std::{ cell::RefCell, - collections::HashMap, fmt::{self, Display}, rc::Rc, time::Instant, @@ -20,6 +19,7 @@ use neqo_http3::{ Http3OrWebTransportStream, Http3Parameters, Http3Server, Http3ServerEvent, StreamId, }; use neqo_transport::{server::ValidateAddress, ConnectionIdGenerator}; +use rustc_hash::FxHashMap as HashMap; use super::{qns_read_response, Args}; use crate::send_data::SendData; @@ -68,8 +68,8 @@ impl HttpServer { } Self { server, - remaining_data: HashMap::new(), - posts: HashMap::new(), + remaining_data: HashMap::default(), + posts: HashMap::default(), is_qns_test: args.shared.qns_test.is_some(), } } diff --git a/neqo-http3/Cargo.toml b/neqo-http3/Cargo.toml index 76cd434b5a..62a529603a 100644 --- a/neqo-http3/Cargo.toml +++ b/neqo-http3/Cargo.toml @@ -23,6 +23,7 @@ neqo-crypto = { path = "./../neqo-crypto" } neqo-qpack = { path = "./../neqo-qpack" } neqo-transport = { path = "./../neqo-transport" } qlog = { workspace = true } +rustc-hash = { workspace = true} sfv = { version = "0.9", default-features = false } url = { workspace = true } diff --git a/neqo-http3/src/connection.rs b/neqo-http3/src/connection.rs index 2e45dd6430..a7c7c14a2d 100644 --- a/neqo-http3/src/connection.rs +++ b/neqo-http3/src/connection.rs @@ -4,13 +4,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::{ - cell::RefCell, - collections::{BTreeSet, HashMap}, - fmt::Debug, - mem, - rc::Rc, -}; +use std::{cell::RefCell, fmt::Debug, mem, rc::Rc}; use neqo_common::{qdebug, qerror, qinfo, qtrace, qwarn, Decoder, Header, MessageType, Role}; use neqo_qpack::{decoder::QPackDecoder, encoder::QPackEncoder}; @@ -18,6 +12,7 @@ use neqo_transport::{ streams::SendOrder, AppError, CloseReason, Connection, DatagramTracking, State, StreamId, StreamType, ZeroRttState, }; +use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet}; use crate::{ client_events::Http3ClientEvents, @@ -302,7 +297,7 @@ pub struct Http3Connection { pub qpack_encoder: Rc>, pub qpack_decoder: Rc>, settings_state: Http3RemoteSettingsState, - streams_with_pending_data: BTreeSet, + streams_with_pending_data: HashSet, pub send_streams: HashMap>, pub recv_streams: HashMap>, webtransport: ExtendedConnectFeature, @@ -333,9 +328,9 @@ impl Http3Connection { ), local_params: conn_params, settings_state: Http3RemoteSettingsState::NotReceived, - streams_with_pending_data: BTreeSet::new(), - send_streams: HashMap::new(), - recv_streams: HashMap::new(), + streams_with_pending_data: HashSet::default(), + send_streams: HashMap::default(), + recv_streams: HashMap::default(), role, } } diff --git a/neqo-http3/src/control_stream_local.rs b/neqo-http3/src/control_stream_local.rs index 3f549c959c..a5cc756cea 100644 --- a/neqo-http3/src/control_stream_local.rs +++ b/neqo-http3/src/control_stream_local.rs @@ -4,10 +4,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::collections::{HashMap, VecDeque}; +use std::collections::VecDeque; use neqo_common::{qtrace, Encoder}; use neqo_transport::{Connection, StreamId, StreamType}; +use rustc_hash::FxHashMap as HashMap; use crate::{frames::HFrame, BufferedStream, Error, Http3StreamType, RecvStream, Res}; diff --git a/neqo-http3/src/features/extended_connect/webtransport_session.rs b/neqo-http3/src/features/extended_connect/webtransport_session.rs index a7aa2fa7b4..b9df8e2eaf 100644 --- a/neqo-http3/src/features/extended_connect/webtransport_session.rs +++ b/neqo-http3/src/features/extended_connect/webtransport_session.rs @@ -4,11 +4,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::{cell::RefCell, collections::BTreeSet, mem, rc::Rc}; +use std::{cell::RefCell, mem, rc::Rc}; use neqo_common::{qtrace, Encoder, Header, MessageType, Role}; use neqo_qpack::{QPackDecoder, QPackEncoder}; use neqo_transport::{Connection, DatagramTracking, StreamId}; +use rustc_hash::FxHashSet as HashSet; use super::{ExtendedConnectEvents, ExtendedConnectType, SessionCloseReason}; use crate::{ @@ -43,8 +44,8 @@ pub struct WebTransportSession { state: SessionState, frame_reader: FrameReader, events: Box, - send_streams: BTreeSet, - recv_streams: BTreeSet, + send_streams: HashSet, + recv_streams: HashSet, role: Role, } @@ -89,8 +90,8 @@ impl WebTransportSession { state: SessionState::Negotiating, frame_reader: FrameReader::new(), events, - send_streams: BTreeSet::new(), - recv_streams: BTreeSet::new(), + send_streams: HashSet::default(), + recv_streams: HashSet::default(), role, } } @@ -123,8 +124,8 @@ impl WebTransportSession { state: SessionState::Active, frame_reader: FrameReader::new(), events, - send_streams: BTreeSet::new(), - recv_streams: BTreeSet::new(), + send_streams: HashSet::default(), + recv_streams: HashSet::default(), role, }) } @@ -324,7 +325,7 @@ impl WebTransportSession { matches!(self.state, SessionState::Active) } - pub fn take_sub_streams(&mut self) -> (BTreeSet, BTreeSet) { + pub fn take_sub_streams(&mut self) -> (HashSet, HashSet) { ( mem::take(&mut self.recv_streams), mem::take(&mut self.send_streams), diff --git a/neqo-http3/src/server.rs b/neqo-http3/src/server.rs index 5a7fdb3668..885d6fe265 100644 --- a/neqo-http3/src/server.rs +++ b/neqo-http3/src/server.rs @@ -6,7 +6,6 @@ use std::{ cell::{RefCell, RefMut}, - collections::HashMap, path::PathBuf, rc::Rc, time::Instant, @@ -18,6 +17,7 @@ use neqo_transport::{ server::{ConnectionRef, Server, ValidateAddress}, ConnectionIdGenerator, Output, }; +use rustc_hash::FxHashMap as HashMap; use crate::{ connection::Http3State, @@ -73,7 +73,7 @@ impl Http3Server { http3_parameters.get_connection_parameters().clone(), )?, http3_parameters, - http3_handlers: HashMap::new(), + http3_handlers: HashMap::default(), events: Http3ServerEvents::default(), }) } diff --git a/neqo-qpack/Cargo.toml b/neqo-qpack/Cargo.toml index ec5aff1222..af11a2a276 100644 --- a/neqo-qpack/Cargo.toml +++ b/neqo-qpack/Cargo.toml @@ -20,6 +20,7 @@ log = { workspace = true } neqo-common = { path = "./../neqo-common" } neqo-transport = { path = "./../neqo-transport" } qlog = { workspace = true } +rustc-hash = { workspace = true } static_assertions = { workspace = true } [dev-dependencies] diff --git a/neqo-qpack/src/encoder.rs b/neqo-qpack/src/encoder.rs index 22bc7c9623..30d4db4290 100644 --- a/neqo-qpack/src/encoder.rs +++ b/neqo-qpack/src/encoder.rs @@ -4,10 +4,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::collections::{HashMap, HashSet, VecDeque}; +use std::collections::VecDeque; use neqo_common::{qdebug, qerror, qlog::NeqoQlog, qtrace, Header}; use neqo_transport::{Connection, Error as TransportError, StreamId}; +use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet}; use crate::{ decoder_instructions::{DecoderInstruction, DecoderInstructionReader}, @@ -68,7 +69,7 @@ impl QPackEncoder { instruction_reader: DecoderInstructionReader::new(), local_stream: LocalStreamState::NoStream, max_blocked_streams: 0, - unacked_header_blocks: HashMap::new(), + unacked_header_blocks: HashMap::default(), blocked_stream_cnt: 0, use_huffman, next_capacity: None, @@ -385,7 +386,7 @@ impl QPackEncoder { let stream_is_blocker = self.is_stream_blocker(stream_id); let can_block = self.blocked_stream_cnt < self.max_blocked_streams || stream_is_blocker; - let mut ref_entries = HashSet::new(); + let mut ref_entries = HashSet::default(); for iter in h { let name = iter.name().as_bytes().to_vec(); diff --git a/neqo-transport/Cargo.toml b/neqo-transport/Cargo.toml index cb5242244b..d9a10cfacf 100644 --- a/neqo-transport/Cargo.toml +++ b/neqo-transport/Cargo.toml @@ -25,6 +25,7 @@ neqo-common = { path = "../neqo-common" } neqo-crypto = { path = "../neqo-crypto" } mtu = { version = "0.2", default-features = false } # neqo is only user currently, can bump freely qlog = { workspace = true } +rustc-hash = { workspace = true } smallvec = { version = "1.13", default-features = false } static_assertions = { workspace = true } strum = { workspace = true } diff --git a/neqo-transport/src/server.rs b/neqo-transport/src/server.rs index 9ed180be95..a99a765c4d 100644 --- a/neqo-transport/src/server.rs +++ b/neqo-transport/src/server.rs @@ -9,7 +9,6 @@ use std::{ cell::RefCell, cmp::min, - collections::HashSet, ops::{Deref, DerefMut}, path::PathBuf, rc::Rc, @@ -24,6 +23,7 @@ use neqo_crypto::{ encode_ech_config, AntiReplay, Cipher, PrivateKey, PublicKey, ZeroRttCheckResult, ZeroRttChecker, }; +use rustc_hash::FxHashSet as HashSet; pub use crate::addr_valid::ValidateAddress; use crate::{