diff --git a/Cargo.lock b/Cargo.lock index 742e3c5..fc8e788 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,11 +74,12 @@ dependencies = [ name = "aquatic_common" version = "0.1.0" dependencies = [ + "ahash 0.7.6", "anyhow", "arc-swap", "hashbrown 0.11.2", "hex", - "indexmap", + "indexmap-amortized", "log", "privdrop", "rand", @@ -99,8 +100,6 @@ dependencies = [ "futures-lite", "futures-rustls", "glommio", - "hashbrown 0.11.2", - "indexmap", "itoa", "log", "memchr", @@ -171,10 +170,8 @@ dependencies = [ "crossbeam-channel", "futures-lite", "glommio", - "hashbrown 0.11.2", "hex", "histogram", - "indexmap", "log", "mimalloc", "mio", @@ -250,7 +247,6 @@ dependencies = [ "futures-rustls", "glommio", "hashbrown 0.11.2", - "indexmap", "log", "mimalloc", "privdrop", @@ -330,6 +326,12 @@ dependencies = [ "tungstenite", ] +[[package]] +name = "atone" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a8a5a5e2e3b1e128ec3783765c91c1f392172c1fffc90fd1b96a13bb18e0dd6" + [[package]] name = "atty" version = "0.2.14" @@ -927,6 +929,15 @@ dependencies = [ "typenum", ] +[[package]] +name = "griddle" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e46a17d0c5d05b045e3814403914aeeb952aa9832f47b1d7ab123ab3d1660454" +dependencies = [ + "hashbrown 0.9.1", +] + [[package]] name = "half" version = "1.8.0" @@ -953,6 +964,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "hashbrown" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" + [[package]] name = "hashbrown" version = "0.11.2" @@ -1013,13 +1030,14 @@ dependencies = [ ] [[package]] -name = "indexmap" -version = "1.7.0" +name = "indexmap-amortized" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +checksum = "81b5a05ffb45214e51fdd40c1f773ab57c74d2a7b41cfadc7ea443acf0359df1" dependencies = [ + "atone", "autocfg", - "hashbrown 0.11.2", + "griddle", ] [[package]] diff --git a/aquatic_common/Cargo.toml b/aquatic_common/Cargo.toml index 3f34d1f..3d9d9b3 100644 --- a/aquatic_common/Cargo.toml +++ b/aquatic_common/Cargo.toml @@ -11,11 +11,12 @@ repository = "https://github.com/greatest-ape/aquatic" name = "aquatic_common" [dependencies] +ahash = "0.7" anyhow = "1" arc-swap = "1" hashbrown = "0.11.2" hex = "0.4" -indexmap = "1" +indexmap-amortized = "1" log = "0.4" privdrop = "0.5" rand = { version = "0.8", features = ["small_rng"] } diff --git a/aquatic_common/src/lib.rs b/aquatic_common/src/lib.rs index 8866e45..58009be 100644 --- a/aquatic_common/src/lib.rs +++ b/aquatic_common/src/lib.rs @@ -1,13 +1,15 @@ use std::net::IpAddr; use std::time::{Duration, Instant}; -use indexmap::IndexMap; +use ahash::RandomState; use rand::Rng; pub mod access_list; pub mod cpu_pinning; pub mod privileges; +pub type AHashIndexMap = indexmap_amortized::IndexMap; + /// Peer or connection valid until this instant /// /// Used instead of "last seen" or similar to hopefully prevent arithmetic @@ -32,7 +34,7 @@ impl ValidUntil { #[inline] pub fn extract_response_peers( rng: &mut impl Rng, - peer_map: &IndexMap, + peer_map: &AHashIndexMap, max_num_peers_to_take: usize, sender_peer_map_key: K, peer_conversion_function: F, diff --git a/aquatic_http/Cargo.toml b/aquatic_http/Cargo.toml index bc0c43b..f6ea2ee 100644 --- a/aquatic_http/Cargo.toml +++ b/aquatic_http/Cargo.toml @@ -26,8 +26,6 @@ either = "1" futures-lite = "1" futures-rustls = "0.22" glommio = { git = "https://github.com/DataDog/glommio.git", rev = "4e6b14772da2f4325271fbcf12d24cf91ed466e5" } -hashbrown = "0.11.2" -indexmap = "1" itoa = "0.4" log = "0.4" mimalloc = { version = "0.1", default-features = false } diff --git a/aquatic_http/src/lib/common.rs b/aquatic_http/src/lib/common.rs index 19e552f..ab499ed 100644 --- a/aquatic_http/src/lib/common.rs +++ b/aquatic_http/src/lib/common.rs @@ -3,9 +3,8 @@ use std::sync::Arc; use std::time::Instant; use aquatic_common::access_list::{create_access_list_cache, AccessListArcSwap, AccessListCache}; +use aquatic_common::AHashIndexMap; use either::Either; -use hashbrown::HashMap; -use indexmap::IndexMap; use smartstring::{LazyCompact, SmartString}; pub use aquatic_common::{convert_ipv4_mapped_ipv6, ValidUntil}; @@ -141,7 +140,7 @@ pub struct PeerMapKey { pub ip_or_key: Either>, } -pub type PeerMap = IndexMap, Peer>; +pub type PeerMap = AHashIndexMap, Peer>; pub struct TorrentData { pub peers: PeerMap, @@ -153,14 +152,14 @@ impl Default for TorrentData { #[inline] fn default() -> Self { Self { - peers: IndexMap::new(), + peers: Default::default(), num_seeders: 0, num_leechers: 0, } } } -pub type TorrentMap = HashMap>; +pub type TorrentMap = AHashIndexMap>; #[derive(Default)] pub struct TorrentMaps { diff --git a/aquatic_udp/Cargo.toml b/aquatic_udp/Cargo.toml index e418054..b0ea491 100644 --- a/aquatic_udp/Cargo.toml +++ b/aquatic_udp/Cargo.toml @@ -26,9 +26,7 @@ aquatic_common = "0.1.0" aquatic_udp_protocol = "0.1.0" cfg-if = "1" core_affinity = "0.5" -hashbrown = "0.11.2" hex = "0.4" -indexmap = "1" log = "0.4" mimalloc = { version = "0.1", default-features = false } parking_lot = "0.11" diff --git a/aquatic_udp/src/lib/common/handlers.rs b/aquatic_udp/src/lib/common/handlers.rs index 380616a..d14b630 100644 --- a/aquatic_udp/src/lib/common/handlers.rs +++ b/aquatic_udp/src/lib/common/handlers.rs @@ -199,7 +199,6 @@ mod tests { use std::collections::HashSet; use std::net::Ipv4Addr; - use indexmap::IndexMap; use quickcheck::{quickcheck, TestResult}; use rand::thread_rng; @@ -229,7 +228,7 @@ mod tests { let gen_num_peers = data.0 as u32; let req_num_peers = data.1 as usize; - let mut peer_map: PeerMap = IndexMap::with_capacity(gen_num_peers as usize); + let mut peer_map: PeerMap = Default::default(); let mut opt_sender_key = None; let mut opt_sender_peer = None; diff --git a/aquatic_udp/src/lib/common/mod.rs b/aquatic_udp/src/lib/common/mod.rs index d448f5a..ea55cce 100644 --- a/aquatic_udp/src/lib/common/mod.rs +++ b/aquatic_udp/src/lib/common/mod.rs @@ -4,8 +4,7 @@ use std::sync::Arc; use std::time::Instant; use aquatic_common::access_list::{create_access_list_cache, AccessListArcSwap}; -use hashbrown::HashMap; -use indexmap::IndexMap; +use aquatic_common::AHashIndexMap; pub use aquatic_common::{access_list::AccessList, ValidUntil}; pub use aquatic_udp_protocol::*; @@ -80,7 +79,7 @@ pub struct PeerMapKey { pub peer_id: PeerId, } -pub type PeerMap = IndexMap, Peer>; +pub type PeerMap = AHashIndexMap, Peer>; pub struct TorrentData { pub peers: PeerMap, @@ -91,14 +90,14 @@ pub struct TorrentData { impl Default for TorrentData { fn default() -> Self { Self { - peers: IndexMap::new(), + peers: Default::default(), num_seeders: 0, num_leechers: 0, } } } -pub type TorrentMap = HashMap>; +pub type TorrentMap = AHashIndexMap>; #[derive(Default)] pub struct TorrentMaps { diff --git a/aquatic_udp/src/lib/common/network.rs b/aquatic_udp/src/lib/common/network.rs index 469d658..e0cd81e 100644 --- a/aquatic_udp/src/lib/common/network.rs +++ b/aquatic_udp/src/lib/common/network.rs @@ -1,11 +1,11 @@ use std::{net::SocketAddr, time::Instant}; +use aquatic_common::AHashIndexMap; pub use aquatic_common::{access_list::AccessList, ValidUntil}; pub use aquatic_udp_protocol::*; -use hashbrown::HashMap; #[derive(Default)] -pub struct ConnectionMap(HashMap<(ConnectionId, SocketAddr), ValidUntil>); +pub struct ConnectionMap(AHashIndexMap<(ConnectionId, SocketAddr), ValidUntil>); impl ConnectionMap { pub fn insert( diff --git a/aquatic_udp/src/lib/glommio/network.rs b/aquatic_udp/src/lib/glommio/network.rs index df5d186..a32917a 100644 --- a/aquatic_udp/src/lib/glommio/network.rs +++ b/aquatic_udp/src/lib/glommio/network.rs @@ -10,6 +10,7 @@ use std::sync::{ use std::time::{Duration, Instant}; use aquatic_common::access_list::create_access_list_cache; +use aquatic_common::AHashIndexMap; use futures_lite::{Stream, StreamExt}; use glommio::channels::channel_mesh::{MeshBuilder, Partial, Role, Senders}; use glommio::channels::local_channel::{new_unbounded, LocalSender}; @@ -17,7 +18,6 @@ use glommio::enclose; use glommio::net::UdpSocket; use glommio::prelude::*; use glommio::timer::TimerActionRepeat; -use hashbrown::HashMap; use rand::prelude::{Rng, SeedableRng, StdRng}; use aquatic_udp_protocol::{IpVersion, Request, Response}; @@ -38,7 +38,7 @@ struct PendingScrapeResponse { } #[derive(Default)] -struct PendingScrapeResponses(HashMap); +struct PendingScrapeResponses(AHashIndexMap); impl PendingScrapeResponses { fn prepare( @@ -266,8 +266,10 @@ async fn read_requests( info_hashes, })) => { if connections.borrow().contains(connection_id, src) { - let mut consumer_requests: HashMap)> = - HashMap::new(); + let mut consumer_requests: AHashIndexMap< + usize, + (ScrapeRequest, Vec), + > = Default::default(); for (i, info_hash) in info_hashes.into_iter().enumerate() { let (req, indices) = consumer_requests diff --git a/aquatic_ws/Cargo.toml b/aquatic_ws/Cargo.toml index f2a41bb..4c58732 100644 --- a/aquatic_ws/Cargo.toml +++ b/aquatic_ws/Cargo.toml @@ -28,7 +28,6 @@ futures = "0.3" futures-rustls = "0.22" glommio = { git = "https://github.com/DataDog/glommio.git", rev = "4e6b14772da2f4325271fbcf12d24cf91ed466e5" } hashbrown = { version = "0.11.2", features = ["serde"] } -indexmap = "1" log = "0.4" mimalloc = { version = "0.1", default-features = false } privdrop = "0.5" diff --git a/aquatic_ws/src/lib/common.rs b/aquatic_ws/src/lib/common.rs index 1b136d9..41cea30 100644 --- a/aquatic_ws/src/lib/common.rs +++ b/aquatic_ws/src/lib/common.rs @@ -3,8 +3,7 @@ use std::sync::Arc; use std::time::Instant; use aquatic_common::access_list::{create_access_list_cache, AccessListArcSwap, AccessListCache}; -use hashbrown::HashMap; -use indexmap::IndexMap; +use aquatic_common::AHashIndexMap; pub use aquatic_common::ValidUntil; @@ -66,7 +65,7 @@ pub struct Peer { pub valid_until: ValidUntil, } -pub type PeerMap = IndexMap; +pub type PeerMap = AHashIndexMap; pub struct TorrentData { pub peers: PeerMap, @@ -78,14 +77,14 @@ impl Default for TorrentData { #[inline] fn default() -> Self { Self { - peers: IndexMap::new(), + peers: Default::default(), num_seeders: 0, num_leechers: 0, } } } -pub type TorrentMap = HashMap; +pub type TorrentMap = AHashIndexMap; #[derive(Default)] pub struct TorrentMaps {