Skip to content

Commit c9b45e6

Browse files
committed
Auto merge of rust-lang#90253 - Kobzol:hash-stable-sort-index-map, r=cjgillot
Change several HashMaps to IndexMap to improve incremental hashing performance Stable hashing hash maps in incremental mode takes a lot of time, especially for some benchmarks like `clap`. As noted by `@Mark-Simulacrum` [here](rust-lang#89404 (comment)), this cost could be reduced by replacing some hash maps by indexmaps. I gathered some statistics and found several hash maps that took a lot of time to hash and replaced them by indexmaps. However, in order for this to work, we need to make sure that these indexmaps have deterministic insertion order. These three are used only in visitors as far as I can see, which seems deterministic. Can we enforce this somehow? Or should some explaining comment be included for these maps?
2 parents af8604f + e475a49 commit c9b45e6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

compiler/rustc_middle/src/middle/region.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/borrow_check.html
88
99
use crate::ty::TyCtxt;
10-
use rustc_data_structures::fx::FxHashMap;
10+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
1111
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1212
use rustc_hir as hir;
1313
use rustc_hir::Node;
@@ -214,14 +214,14 @@ pub struct ScopeTree {
214214
/// conditional expression or repeating block. (Note that the
215215
/// enclosing scope ID for the block associated with a closure is
216216
/// the closure itself.)
217-
pub parent_map: FxHashMap<Scope, (Scope, ScopeDepth)>,
217+
pub parent_map: FxIndexMap<Scope, (Scope, ScopeDepth)>,
218218

219219
/// Maps from a variable or binding ID to the block in which that
220220
/// variable is declared.
221-
var_map: FxHashMap<hir::ItemLocalId, Scope>,
221+
var_map: FxIndexMap<hir::ItemLocalId, Scope>,
222222

223223
/// Maps from a `NodeId` to the associated destruction scope (if any).
224-
destruction_scopes: FxHashMap<hir::ItemLocalId, Scope>,
224+
destruction_scopes: FxIndexMap<hir::ItemLocalId, Scope>,
225225

226226
/// `rvalue_scopes` includes entries for those expressions whose
227227
/// cleanup scope is larger than the default. The map goes from the

0 commit comments

Comments
 (0)