perf(common): Use fxhash everywhere (#3985)

Description:
 - To avoid a breaking change, I created a cargo feature that can be used to change hasher.
 - This leads to about 8% perf improvements on m1 max macbook pro 64gb
This commit is contained in:
Donny/강동윤 2022-03-12 16:15:12 +09:00 committed by GitHub
parent fb421b8cc3
commit db60291164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 3 deletions

1
Cargo.lock generated
View File

@ -3752,6 +3752,7 @@ version = "0.5.1"
dependencies = [
"fastmem",
"mimalloc-rust",
"swc_common",
]
[[package]]

View File

@ -17,6 +17,7 @@ concurrent = ["parking_lot"]
debug = []
default = []
diagnostic-serde = []
perf = ["parking_lot"]
plugin-base = ["anyhow", "rkyv-impl", "diagnostic-serde"]
plugin-mode = ["plugin-base"]
plugin-rt = ["plugin-base"]

View File

@ -1,5 +1,27 @@
use std::collections::{HashMap, HashSet};
#[cfg(not(feature = "perf"))]
pub use self::ahash::*;
#[cfg(feature = "perf")]
pub use self::fxhash::*;
pub type AHashMap<K, V> = HashMap<K, V, ahash::RandomState>;
#[cfg(feature = "perf")]
mod fxhash {
use std::{
collections::{HashMap, HashSet},
hash::BuildHasherDefault,
};
pub type AHashSet<V> = HashSet<V, ahash::RandomState>;
use rustc_hash::FxHasher;
pub type AHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
pub type AHashSet<V> = HashSet<V, BuildHasherDefault<FxHasher>>;
}
#[cfg(not(feature = "perf"))]
mod ahash {
use std::collections::{HashMap, HashSet};
pub type AHashMap<K, V> = HashMap<K, V, ahash::RandomState>;
pub type AHashSet<V> = HashSet<V, ahash::RandomState>;
}

View File

@ -26,6 +26,11 @@
//! ## `plugin-mode`
//!
//! Allows replacing operations related to thread-local variables with a trait.
//!
//!
//! ## `perf`
//!
//! Use `fxhash` instead of `ahash` for `AHashMap` and `AHashSet`.
#![deny(clippy::all)]
#![deny(unused)]
#![cfg_attr(docsrs, feature(doc_cfg))]

View File

@ -12,6 +12,7 @@ version = "0.5.1"
[dependencies]
fastmem = {version = "0.1.0", path = "../fastmem", features = ["enable"]}
swc_common = {version = "0.17.14", path = "../swc_common", features = ["perf"]}
[target.'cfg(not(all(target_os = "linux", target_arch = "aarch64", target_env = "musl")))'.dependencies]
mimalloc-rust = "=0.1.5"