diff --git a/Cargo.lock b/Cargo.lock index e00690c..2d96f21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,6 +213,7 @@ dependencies = [ "cfg-if", "crossbeam-channel", "getrandom", + "hashbrown 0.12.0", "hex", "log", "mimalloc", diff --git a/aquatic_udp/Cargo.toml b/aquatic_udp/Cargo.toml index d9456d8..aaf51c5 100644 --- a/aquatic_udp/Cargo.toml +++ b/aquatic_udp/Cargo.toml @@ -28,6 +28,7 @@ blake3 = "1" cfg-if = "1" crossbeam-channel = "0.5" getrandom = "0.2" +hashbrown = { version = "0.12", default-features = false } hex = "0.4" log = "0.4" mimalloc = { version = "0.1", default-features = false } diff --git a/aquatic_udp/src/workers/socket.rs b/aquatic_udp/src/workers/socket.rs index 161cf62..a571e6c 100644 --- a/aquatic_udp/src/workers/socket.rs +++ b/aquatic_udp/src/workers/socket.rs @@ -7,13 +7,14 @@ use std::vec::Drain; use anyhow::Context; use aquatic_common::privileges::PrivilegeDropper; use crossbeam_channel::Receiver; +use hashbrown::HashMap; use mio::net::UdpSocket; use mio::{Events, Interest, Poll, Token}; use slab::Slab; use aquatic_common::access_list::create_access_list_cache; use aquatic_common::access_list::AccessListCache; -use aquatic_common::{AmortizedIndexMap, CanonicalSocketAddr}; +use aquatic_common::CanonicalSocketAddr; use aquatic_common::{PanicSentinel, ValidUntil}; use aquatic_udp_protocol::*; use socket2::{Domain, Protocol, Socket, Type}; @@ -39,8 +40,9 @@ impl PendingScrapeResponseSlab { request: ScrapeRequest, valid_until: ValidUntil, ) -> impl IntoIterator { - let mut split_requests: AmortizedIndexMap = - Default::default(); + let capacity = config.request_workers.min(request.info_hashes.len()); + let mut split_requests: HashMap = + HashMap::with_capacity(capacity); if request.info_hashes.is_empty() { ::log::warn!(