mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 18:55:32 +00:00
Replace HashMap and IndexMap with indexmap_amortized
This will hopefully get down latency.
This commit is contained in:
parent
362ee7274f
commit
b8073e4bd1
12 changed files with 55 additions and 41 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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<Ipv4Addr> = IndexMap::with_capacity(gen_num_peers as usize);
|
||||
let mut peer_map: PeerMap<Ipv4Addr> = Default::default();
|
||||
|
||||
let mut opt_sender_key = None;
|
||||
let mut opt_sender_peer = None;
|
||||
|
|
|
|||
|
|
@ -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<I: Ip> {
|
|||
pub peer_id: PeerId,
|
||||
}
|
||||
|
||||
pub type PeerMap<I> = IndexMap<PeerMapKey<I>, Peer<I>>;
|
||||
pub type PeerMap<I> = AHashIndexMap<PeerMapKey<I>, Peer<I>>;
|
||||
|
||||
pub struct TorrentData<I: Ip> {
|
||||
pub peers: PeerMap<I>,
|
||||
|
|
@ -91,14 +90,14 @@ pub struct TorrentData<I: Ip> {
|
|||
impl<I: Ip> Default for TorrentData<I> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
peers: IndexMap::new(),
|
||||
peers: Default::default(),
|
||||
num_seeders: 0,
|
||||
num_leechers: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type TorrentMap<I> = HashMap<InfoHash, TorrentData<I>>;
|
||||
pub type TorrentMap<I> = AHashIndexMap<InfoHash, TorrentData<I>>;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct TorrentMaps {
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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<TransactionId, PendingScrapeResponse>);
|
||||
struct PendingScrapeResponses(AHashIndexMap<TransactionId, PendingScrapeResponse>);
|
||||
|
||||
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<usize, (ScrapeRequest, Vec<usize>)> =
|
||||
HashMap::new();
|
||||
let mut consumer_requests: AHashIndexMap<
|
||||
usize,
|
||||
(ScrapeRequest, Vec<usize>),
|
||||
> = Default::default();
|
||||
|
||||
for (i, info_hash) in info_hashes.into_iter().enumerate() {
|
||||
let (req, indices) = consumer_requests
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue