Replace HashMap and IndexMap with indexmap_amortized

This will hopefully get down latency.
This commit is contained in:
Joakim Frostegård 2021-11-03 10:35:29 +01:00
parent 362ee7274f
commit b8073e4bd1
12 changed files with 55 additions and 41 deletions

View file

@ -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"] }

View file

@ -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<K, V> = indexmap_amortized::IndexMap<K, V, RandomState>;
/// 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<K, V, R, F>(
rng: &mut impl Rng,
peer_map: &IndexMap<K, V>,
peer_map: &AHashIndexMap<K, V>,
max_num_peers_to_take: usize,
sender_peer_map_key: K,
peer_conversion_function: F,