swc/crates/swc_common/src/collections.rs
Donny/강동윤 db60291164
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
2022-03-12 07:15:12 +00:00

28 lines
636 B
Rust

#[cfg(not(feature = "perf"))]
pub use self::ahash::*;
#[cfg(feature = "perf")]
pub use self::fxhash::*;
#[cfg(feature = "perf")]
mod fxhash {
use std::{
collections::{HashMap, HashSet},
hash::BuildHasherDefault,
};
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>;
}