Skip to content

Commit 0fad4cd

Browse files
committed
Auto merge of rust-lang#127040 - blyxyas:xxh3-hasher, r=<try>
[Perf Experiment] Change FxHash to GxHash I've done some experiments comparing hashing libraries that can be found in crates.io, and it while FxHash is faster than the default hasher, Gxhash is still about 10 times faster than fxhash. This is just with the default implementation, the library permits customization using CPU-specific optimizations. But we can ask the maintainers for that if we were to verify that the optimization is big enough.
2 parents 2495953 + 4ada799 commit 0fad4cd

File tree

365 files changed

+1749
-1693
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

365 files changed

+1749
-1693
lines changed

Cargo.lock

+25-9
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ dependencies = [
13821382
"fluent-syntax",
13831383
"intl-memoizer",
13841384
"intl_pluralrules",
1385-
"rustc-hash",
1385+
"rustc-hash 1.1.0",
13861386
"self_cell 0.10.3",
13871387
"smallvec",
13881388
"unic-langid",
@@ -1646,6 +1646,15 @@ dependencies = [
16461646
"serde",
16471647
]
16481648

1649+
[[package]]
1650+
name = "gxhash"
1651+
version = "3.4.1"
1652+
source = "registry+https://github.com/rust-lang/crates.io-index"
1653+
checksum = "a197c9b654827513cf53842c5c6d3da2b4b35a785f8e0eff78bdf8e445aba1bb"
1654+
dependencies = [
1655+
"rustversion",
1656+
]
1657+
16491658
[[package]]
16501659
name = "handlebars"
16511660
version = "5.1.2"
@@ -2074,7 +2083,7 @@ dependencies = [
20742083
"anyhow",
20752084
"clap",
20762085
"fs-err",
2077-
"rustc-hash",
2086+
"rustc-hash 1.1.0",
20782087
"rustdoc-json-types",
20792088
"serde",
20802089
"serde_json",
@@ -2406,7 +2415,7 @@ dependencies = [
24062415
"memmap2",
24072416
"parking_lot",
24082417
"perf-event-open-sys",
2409-
"rustc-hash",
2418+
"rustc-hash 1.1.0",
24102419
"smallvec",
24112420
]
24122421

@@ -3016,7 +3025,7 @@ checksum = "c4e8e505342045d397d0b6674dcb82d6faf5cf40484d30eeb88fc82ef14e903f"
30163025
dependencies = [
30173026
"datafrog",
30183027
"log",
3019-
"rustc-hash",
3028+
"rustc-hash 1.1.0",
30203029
]
30213030

30223031
[[package]]
@@ -3448,6 +3457,12 @@ version = "1.1.0"
34483457
source = "registry+https://github.com/rust-lang/crates.io-index"
34493458
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
34503459

3460+
[[package]]
3461+
name = "rustc-hash"
3462+
version = "2.0.0"
3463+
source = "registry+https://github.com/rust-lang/crates.io-index"
3464+
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
3465+
34513466
[[package]]
34523467
name = "rustc-main"
34533468
version = "0.0.0"
@@ -3817,14 +3832,15 @@ dependencies = [
38173832
"either",
38183833
"elsa",
38193834
"ena",
3835+
"gxhash",
38203836
"indexmap",
38213837
"jobserver",
38223838
"libc",
38233839
"measureme",
38243840
"memmap2",
38253841
"parking_lot",
38263842
"portable-atomic",
3827-
"rustc-hash",
3843+
"rustc-hash 2.0.0",
38283844
"rustc-rayon",
38293845
"rustc_arena",
38303846
"rustc_graphviz",
@@ -4512,7 +4528,7 @@ dependencies = [
45124528
name = "rustc_pattern_analysis"
45134529
version = "0.0.0"
45144530
dependencies = [
4515-
"rustc-hash",
4531+
"rustc-hash 1.1.0",
45164532
"rustc_apfloat",
45174533
"rustc_arena",
45184534
"rustc_data_structures",
@@ -4904,7 +4920,7 @@ name = "rustdoc-json-types"
49044920
version = "0.1.0"
49054921
dependencies = [
49064922
"bincode",
4907-
"rustc-hash",
4923+
"rustc-hash 1.1.0",
49084924
"serde",
49094925
"serde_json",
49104926
]
@@ -5632,7 +5648,7 @@ dependencies = [
56325648
"ignore",
56335649
"miropt-test-tools",
56345650
"regex",
5635-
"rustc-hash",
5651+
"rustc-hash 1.1.0",
56365652
"semver",
56375653
"similar",
56385654
"termcolor",
@@ -5886,7 +5902,7 @@ version = "0.5.0"
58865902
source = "registry+https://github.com/rust-lang/crates.io-index"
58875903
checksum = "deb68604048ff8fa93347f02441e4487594adc20bb8a084f9e564d2b827a0a9f"
58885904
dependencies = [
5889-
"rustc-hash",
5905+
"rustc-hash 1.1.0",
58905906
]
58915907

58925908
[[package]]

blah.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hola1

compiler/rustc_ast/src/format.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::ptr::P;
22
use crate::Expr;
3-
use rustc_data_structures::fx::FxHashMap;
3+
use rustc_data_structures::gx::GxHashMap;
44
use rustc_macros::{Decodable, Encodable};
55
use rustc_span::symbol::{Ident, Symbol};
66
use rustc_span::Span;
@@ -65,14 +65,14 @@ pub struct FormatArguments {
6565
arguments: Vec<FormatArgument>,
6666
num_unnamed_args: usize,
6767
num_explicit_args: usize,
68-
names: FxHashMap<Symbol, usize>,
68+
names: GxHashMap<Symbol, usize>,
6969
}
7070

7171
impl FormatArguments {
7272
pub fn new() -> Self {
7373
Self {
7474
arguments: Vec::new(),
75-
names: FxHashMap::default(),
75+
names: GxHashMap::default(),
7676
num_unnamed_args: 0,
7777
num_explicit_args: 0,
7878
}

compiler/rustc_ast_lowering/src/asm.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::LoweringContext;
1111

1212
use rustc_ast::ptr::P;
1313
use rustc_ast::*;
14-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
14+
use rustc_data_structures::gx::{GxHashMap, GxHashSet, GxIndexMap};
1515
use rustc_hir as hir;
1616
use rustc_hir::def::{DefKind, Res};
1717
use rustc_session::parse::feature_err;
@@ -68,7 +68,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
6868
.emit();
6969
}
7070

71-
let mut clobber_abis = FxIndexMap::default();
71+
let mut clobber_abis = GxIndexMap::default();
7272
if let Some(asm_arch) = asm_arch {
7373
for (abi_name, abi_span) in &asm.clobber_abis {
7474
match asm::InlineAsmClobberAbi::parse(asm_arch, &self.tcx.sess.target, *abi_name) {
@@ -318,8 +318,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
318318
}
319319
}
320320

321-
let mut used_input_regs = FxHashMap::default();
322-
let mut used_output_regs = FxHashMap::default();
321+
let mut used_input_regs = GxHashMap::default();
322+
let mut used_output_regs = GxHashMap::default();
323323

324324
for (idx, &(ref op, op_sp)) in operands.iter().enumerate() {
325325
if let Some(reg) = op.reg() {
@@ -362,7 +362,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
362362
// Flag to output the error only once per operand
363363
let mut skip = false;
364364

365-
let mut check = |used_regs: &mut FxHashMap<asm::InlineAsmReg, usize>,
365+
let mut check = |used_regs: &mut GxHashMap<asm::InlineAsmReg, usize>,
366366
input,
367367
r: asm::InlineAsmReg| {
368368
match used_regs.entry(r) {
@@ -436,7 +436,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
436436

437437
// If a clobber_abi is specified, add the necessary clobbers to the
438438
// operands list.
439-
let mut clobbered = FxHashSet::default();
439+
let mut clobbered = GxHashSet::default();
440440
for (abi, (_, abi_span)) in clobber_abis {
441441
for &clobber in abi.clobbered_regs() {
442442
// Don't emit a clobber for a register already clobbered

compiler/rustc_ast_lowering/src/format.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::ops::ControlFlow;
33
use rustc_ast as ast;
44
use rustc_ast::visit::Visitor;
55
use rustc_ast::*;
6-
use rustc_data_structures::fx::FxIndexMap;
6+
use rustc_data_structures::gx::GxIndexMap;
77
use rustc_hir as hir;
88
use rustc_span::{
99
sym,
@@ -282,7 +282,7 @@ fn make_count<'hir>(
282282
ctx: &mut LoweringContext<'_, 'hir>,
283283
sp: Span,
284284
count: &Option<FormatCount>,
285-
argmap: &mut FxIndexMap<(usize, ArgumentType), Option<Span>>,
285+
argmap: &mut GxIndexMap<(usize, ArgumentType), Option<Span>>,
286286
) -> hir::Expr<'hir> {
287287
match count {
288288
Some(FormatCount::Literal(n)) => {
@@ -335,7 +335,7 @@ fn make_format_spec<'hir>(
335335
ctx: &mut LoweringContext<'_, 'hir>,
336336
sp: Span,
337337
placeholder: &FormatPlaceholder,
338-
argmap: &mut FxIndexMap<(usize, ArgumentType), Option<Span>>,
338+
argmap: &mut GxIndexMap<(usize, ArgumentType), Option<Span>>,
339339
) -> hir::Expr<'hir> {
340340
let position = match placeholder.argument.index {
341341
Ok(arg_index) => {
@@ -432,7 +432,7 @@ fn expand_format_args<'hir>(
432432

433433
// Create a list of all _unique_ (argument, format trait) combinations.
434434
// E.g. "{0} {0:x} {0} {1}" -> [(0, Display), (0, LowerHex), (1, Display)]
435-
let mut argmap = FxIndexMap::default();
435+
let mut argmap = GxIndexMap::default();
436436
for piece in &fmt.template {
437437
let FormatArgsPiece::Placeholder(placeholder) = piece else { continue };
438438
if placeholder.format_options != Default::default() {

compiler/rustc_ast_lowering/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use rustc_ast::{self as ast, *};
4646
use rustc_ast_pretty::pprust;
4747
use rustc_data_structures::captures::Captures;
4848
use rustc_data_structures::fingerprint::Fingerprint;
49-
use rustc_data_structures::fx::FxIndexSet;
49+
use rustc_data_structures::gx::GxIndexSet;
5050
use rustc_data_structures::sorted_map::SortedMap;
5151
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
5252
use rustc_data_structures::sync::Lrc;
@@ -1630,7 +1630,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16301630
opaque_ty_node_id: NodeId,
16311631
origin: hir::OpaqueTyOrigin,
16321632
in_trait: bool,
1633-
captured_lifetimes_to_duplicate: FxIndexSet<Lifetime>,
1633+
captured_lifetimes_to_duplicate: GxIndexSet<Lifetime>,
16341634
span: Span,
16351635
opaque_ty_span: Span,
16361636
lower_item_bounds: impl FnOnce(&mut Self) -> &'hir [hir::GenericBound<'hir>],

compiler/rustc_ast_lowering/src/lifetime_collector.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::ResolverAstLoweringExt;
22
use rustc_ast::visit::{self, BoundKind, LifetimeCtxt, Visitor};
33
use rustc_ast::{GenericBounds, Lifetime, NodeId, PathSegment, PolyTraitRef, Ty, TyKind};
4-
use rustc_data_structures::fx::FxIndexSet;
4+
use rustc_data_structures::gx::GxIndexSet;
55
use rustc_hir::def::{DefKind, LifetimeRes, Res};
66
use rustc_middle::span_bug;
77
use rustc_middle::ty::ResolverAstLowering;
@@ -11,12 +11,12 @@ use rustc_span::Span;
1111
struct LifetimeCollectVisitor<'ast> {
1212
resolver: &'ast ResolverAstLowering,
1313
current_binders: Vec<NodeId>,
14-
collected_lifetimes: FxIndexSet<Lifetime>,
14+
collected_lifetimes: GxIndexSet<Lifetime>,
1515
}
1616

1717
impl<'ast> LifetimeCollectVisitor<'ast> {
1818
fn new(resolver: &'ast ResolverAstLowering) -> Self {
19-
Self { resolver, current_binders: Vec::new(), collected_lifetimes: FxIndexSet::default() }
19+
Self { resolver, current_binders: Vec::new(), collected_lifetimes: GxIndexSet::default() }
2020
}
2121

2222
fn record_lifetime_use(&mut self, lifetime: Lifetime) {
@@ -108,7 +108,7 @@ impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
108108
pub(crate) fn lifetimes_in_bounds(
109109
resolver: &ResolverAstLowering,
110110
bounds: &GenericBounds,
111-
) -> FxIndexSet<Lifetime> {
111+
) -> GxIndexSet<Lifetime> {
112112
let mut visitor = LifetimeCollectVisitor::new(resolver);
113113
for bound in bounds {
114114
visitor.visit_param_bound(bound, BoundKind::Bound);

compiler/rustc_ast_passes/src/ast_validation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_ast::ptr::P;
1111
use rustc_ast::visit::{walk_list, AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor};
1212
use rustc_ast::*;
1313
use rustc_ast_pretty::pprust::{self, State};
14-
use rustc_data_structures::fx::FxIndexMap;
14+
use rustc_data_structures::gx::GxIndexMap;
1515
use rustc_errors::DiagCtxtHandle;
1616
use rustc_feature::Features;
1717
use rustc_parse::validate_attr;
@@ -828,7 +828,7 @@ impl<'a> AstValidator<'a> {
828828
/// which is lifetimes, then types and then consts. (`<'a, T, const N: usize>`)
829829
fn validate_generic_param_order(dcx: DiagCtxtHandle<'_>, generics: &[GenericParam], span: Span) {
830830
let mut max_param: Option<ParamKindOrd> = None;
831-
let mut out_of_order = FxIndexMap::default();
831+
let mut out_of_order = GxIndexMap::default();
832832
let mut param_idents = Vec::with_capacity(generics.len());
833833

834834
for (idx, param) in generics.iter().enumerate() {

compiler/rustc_borrowck/src/borrow_set.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::path_utils::allow_two_phase_borrow;
22
use crate::place_ext::PlaceExt;
33
use crate::BorrowIndex;
4-
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
4+
use rustc_data_structures::gx::{GxIndexMap, GxIndexSet};
55
use rustc_index::bit_set::BitSet;
66
use rustc_middle::mir::traversal;
77
use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor};
@@ -18,16 +18,16 @@ pub struct BorrowSet<'tcx> {
1818
/// by the `Location` of the assignment statement in which it
1919
/// appears on the right hand side. Thus the location is the map
2020
/// key, and its position in the map corresponds to `BorrowIndex`.
21-
pub location_map: FxIndexMap<Location, BorrowData<'tcx>>,
21+
pub location_map: GxIndexMap<Location, BorrowData<'tcx>>,
2222

2323
/// Locations which activate borrows.
2424
/// NOTE: a given location may activate more than one borrow in the future
2525
/// when more general two-phase borrow support is introduced, but for now we
2626
/// only need to store one borrow index.
27-
pub activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
27+
pub activation_map: GxIndexMap<Location, Vec<BorrowIndex>>,
2828

2929
/// Map from local to all the borrows on that local.
30-
pub local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>,
30+
pub local_map: GxIndexMap<mir::Local, GxIndexSet<BorrowIndex>>,
3131

3232
pub locals_state_at_exit: LocalsStateAtExit,
3333
}
@@ -174,9 +174,9 @@ impl<'tcx> BorrowSet<'tcx> {
174174
struct GatherBorrows<'a, 'tcx> {
175175
tcx: TyCtxt<'tcx>,
176176
body: &'a Body<'tcx>,
177-
location_map: FxIndexMap<Location, BorrowData<'tcx>>,
178-
activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
179-
local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>,
177+
location_map: GxIndexMap<Location, BorrowData<'tcx>>,
178+
activation_map: GxIndexMap<Location, Vec<BorrowIndex>>,
179+
local_map: GxIndexMap<mir::Local, GxIndexSet<BorrowIndex>>,
180180

181181
/// When we encounter a 2-phase borrow statement, it will always
182182
/// be assigning into a temporary TEMP:
@@ -186,7 +186,7 @@ struct GatherBorrows<'a, 'tcx> {
186186
/// We add TEMP into this map with `b`, where `b` is the index of
187187
/// the borrow. When we find a later use of this activation, we
188188
/// remove from the map (and add to the "tombstone" set below).
189-
pending_activations: FxIndexMap<mir::Local, BorrowIndex>,
189+
pending_activations: GxIndexMap<mir::Local, BorrowIndex>,
190190

191191
locals_state_at_exit: LocalsStateAtExit,
192192
}

0 commit comments

Comments
 (0)