mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 21:54:36 +03:00
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:
parent
fb421b8cc3
commit
db60291164
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3752,6 +3752,7 @@ version = "0.5.1"
|
||||
dependencies = [
|
||||
"fastmem",
|
||||
"mimalloc-rust",
|
||||
"swc_common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -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"]
|
||||
|
@ -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>;
|
||||
}
|
||||
|
@ -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))]
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user