use faster ahash maps

This commit is contained in:
Rob Ede 2021-01-02 20:03:18 +00:00
parent a919d2de56
commit 22749150ae
No known key found for this signature in database
GPG Key ID: C2A3B36E841A91E6
5 changed files with 18 additions and 19 deletions

View File

@ -58,7 +58,7 @@ encoding_rs = "0.8"
futures-channel = { version = "0.3.7", default-features = false }
futures-core = { version = "0.3.7", default-features = false }
futures-util = { version = "0.3.7", default-features = false, features = ["sink"] }
fxhash = "0.2.1"
ahash = "0.6"
h2 = "0.3.0"
http = "0.2.2"
httparse = "1.3"

View File

@ -13,7 +13,7 @@ use actix_utils::task::LocalWaker;
use bytes::Bytes;
use futures_channel::oneshot;
use futures_util::future::{poll_fn, FutureExt, LocalBoxFuture};
use fxhash::FxHashMap;
use ahash::AHashMap;
use h2::client::{Connection, SendRequest};
use http::uri::Authority;
use indexmap::IndexSet;
@ -59,7 +59,7 @@ where
acquired: 0,
waiters: Slab::new(),
waiters_queue: IndexSet::new(),
available: FxHashMap::default(),
available: AHashMap::default(),
waker: LocalWaker::new(),
}));
@ -257,7 +257,7 @@ struct AvailableConnection<Io> {
pub(crate) struct Inner<Io> {
config: ConnectorConfig,
acquired: usize,
available: FxHashMap<Key, VecDeque<AvailableConnection<Io>>>,
available: AHashMap<Key, VecDeque<AvailableConnection<Io>>>,
waiters: Slab<
Option<(
Connect,

View File

@ -1,14 +1,16 @@
use std::any::{Any, TypeId};
use std::{fmt, mem};
use std::{
any::{Any, TypeId},
fmt, mem,
};
use fxhash::FxHashMap;
use ahash::AHashMap;
/// A type map of request extensions.
#[derive(Default)]
pub struct Extensions {
/// Use FxHasher with a std HashMap with for faster
/// lookups on the small `TypeId` (u64 equivalent) keys.
map: FxHashMap<TypeId, Box<dyn Any>>,
map: AHashMap<TypeId, Box<dyn Any>>,
}
impl Extensions {
@ -16,7 +18,7 @@ impl Extensions {
#[inline]
pub fn new() -> Extensions {
Extensions {
map: FxHashMap::default(),
map: AHashMap::default(),
}
}

View File

@ -1,8 +1,7 @@
use std::collections::hash_map::{self, Entry};
use std::convert::TryFrom;
use std::{collections::hash_map::{self, Entry}, convert::TryFrom};
use ahash::AHashMap;
use either::Either;
use fxhash::FxHashMap;
use http::header::{HeaderName, HeaderValue};
/// A set of HTTP headers
@ -10,7 +9,7 @@ use http::header::{HeaderName, HeaderValue};
/// `HeaderMap` is an multi-map of [`HeaderName`] to values.
#[derive(Debug, Clone)]
pub struct HeaderMap {
pub(crate) inner: FxHashMap<HeaderName, Value>,
pub(crate) inner: AHashMap<HeaderName, Value>,
}
#[derive(Debug, Clone)]
@ -55,7 +54,7 @@ impl HeaderMap {
/// allocate.
pub fn new() -> Self {
HeaderMap {
inner: FxHashMap::default(),
inner: AHashMap::default(),
}
}
@ -69,7 +68,7 @@ impl HeaderMap {
/// More capacity than requested may be allocated.
pub fn with_capacity(capacity: usize) -> HeaderMap {
HeaderMap {
inner: FxHashMap::with_capacity_and_hasher(capacity, Default::default()),
inner: AHashMap::with_capacity_and_hasher(capacity, Default::default()),
}
}

View File

@ -1,8 +1,6 @@
//! Various http headers
// This is mostly copy of [hyper](https://github.com/hyperium/hyper/tree/master/src/header)
//! Various HTTP headers.
use std::convert::TryFrom;
use std::{fmt, str::FromStr};
use std::{convert::TryFrom, fmt, str::FromStr};
use bytes::{Bytes, BytesMut};
use http::Error as HttpError;