Skip to content

[Performance run] Switch rustc_hash -> ahash #78218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ dependencies = [
"rustc-std-workspace-core",
]

[[package]]
name = "ahash"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eb6ec8807cd25b59e6b8100815afc73f54e294f1a425a2e555971969889a8f8"
dependencies = [
"getrandom 0.2.0",
"lazy_static",
]

[[package]]
name = "aho-corasick"
version = "0.7.13"
Expand Down Expand Up @@ -3572,6 +3582,7 @@ dependencies = [
name = "rustc_data_structures"
version = "0.0.0"
dependencies = [
"ahash",
"arrayvec",
"bitflags",
"cfg-if 0.1.10",
Expand All @@ -3582,7 +3593,6 @@ dependencies = [
"libc",
"measureme",
"parking_lot 0.11.0",
"rustc-hash",
"rustc-rayon",
"rustc-rayon-core",
"rustc_graphviz",
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ crossbeam-utils = { version = "0.7", features = ["nightly"] }
stable_deref_trait = "1.0.0"
rayon = { version = "0.3.0", package = "rustc-rayon" }
rayon-core = { version = "0.3.0", package = "rustc-rayon-core" }
rustc-hash = "1.1.0"
#rustc-hash = "1.1.0"
ahash = { version = "0.5.6", features = ["specialize"] }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
rustc_index = { path = "../rustc_index", package = "rustc_index" }
bitflags = "1.2.1"
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_data_structures/src/fx.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
pub use ahash::AHasher as FxHasher;
use ahash::RandomState;
use std::collections::{HashMap, HashSet};
use std::hash::BuildHasherDefault;

pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
//pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher};

pub type FxHashMap<K, V> = HashMap<K, V, RandomState>;
pub type FxHashSet<T> = HashSet<T, RandomState>;

pub type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
pub type FxIndexSet<V> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>>;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/stable_map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use rustc_hash::FxHashMap;
pub use crate::fx::FxHashMap;
use std::borrow::Borrow;
use std::collections::hash_map::Entry;
use std::fmt;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/stable_set.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use rustc_hash::FxHashSet;
pub use crate::fx::FxHashSet;
use std::borrow::Borrow;
use std::fmt;
use std::hash::Hash;
Expand Down
7 changes: 4 additions & 3 deletions src/tools/clippy/clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use std::mem;
use if_chain::if_chain;
use rustc_ast::ast::{self, Attribute, LitKind};
use rustc_attr as attr;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::FxHasher;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
Expand Down Expand Up @@ -1500,8 +1500,9 @@ where

let mut match_expr_list: Vec<(&T, &T)> = Vec::new();

let mut map: FxHashMap<_, Vec<&_>> =
FxHashMap::with_capacity_and_hasher(exprs.len(), BuildHasherDefault::default());
use std::collections::HashMap;
let mut map: HashMap<_, Vec<&_>, BuildHasherDefault<FxHasher>> =
HashMap::with_capacity_and_hasher(exprs.len(), BuildHasherDefault::default());

for expr in exprs {
match map.entry(hash(expr)) {
Expand Down