perf: use ahash

This commit is contained in:
Shunsuke Shibayama 2024-10-03 19:35:05 +09:00
parent d230bb7374
commit 7af8efae2f
4 changed files with 57 additions and 3 deletions

51
Cargo.lock generated
View file

@ -17,6 +17,19 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]]
name = "ahash"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
dependencies = [
"cfg-if",
"getrandom",
"once_cell",
"version_check",
"zerocopy",
]
[[package]]
name = "autocfg"
version = "1.4.0"
@ -130,6 +143,7 @@ dependencies = [
name = "erg_common"
version = "0.6.45"
dependencies = [
"ahash",
"backtrace-on-stack-overflow",
"crossterm",
"erg_proc_macros",
@ -184,6 +198,17 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "getrandom"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "gimli"
version = "0.31.0"
@ -666,6 +691,12 @@ dependencies = [
"serde",
]
[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "w-boson"
version = "0.1.0"
@ -896,3 +927,23 @@ name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "zerocopy"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
]

View file

@ -37,6 +37,7 @@ w-boson = { version = "0.1.0", optional = true }
crossterm = { optional = true, version = "0.25.0" }
parking_lot = "0.12"
thread_local = "1.1"
ahash = "0.8"
pyo3 = { workspace = true, optional = true }
erg_proc_macros = { workspace = true }

View file

@ -37,9 +37,11 @@ use core::mem::size_of;
use core::ops::BitXor;
use std::collections::{HashMap, HashSet};
use ahash::AHasher;
/// Type alias for a hashmap using the `fx` hash algorithm.
pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
pub type FxHashSet<T> = HashSet<T, BuildHasherDefault<FxHasher>>;
pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<AHasher>>;
pub type FxHashSet<T> = HashSet<T, BuildHasherDefault<AHasher>>;
/// A speedy hash algorithm for use within rustc. The hashmap in liballoc
/// by default uses SipHash which isn't quite as speedy as we want. In the

View file

@ -103,7 +103,7 @@ pub fn fmt_indent(s: String, depth: usize) -> String {
/// If you want to get a hash consisting of multiple objects, pass it as a tuple or array
pub fn get_hash<T: std::hash::Hash>(t: &T) -> usize {
let mut s = fxhash::FxHasher::default();
let mut s = ahash::AHasher::default();
t.hash(&mut s);
let res = std::hash::Hasher::finish(&s);
if cfg!(target_pointer_width = "64") {