Skip to content

Commit 4f47a16

Browse files
authored
Unrolled build for #160811
Rollup merge of #160811 - zalanlevai:160464-perf-regression, r=JonathanBrouwer Fix `visible_parent_map` fallback map merging perf regression This PR attempts to fix the `visible_parent_map` perf regression introduced in #160464, which was found in a [post-merge perf run](#160464 (comment)). Because the original PR fixes unnecessary iterations in the breadth-first search (BFS), meaning that it only reduces the amount of work during the BFS, the likely cause of the perf regression is the changed merging of the fallback map into the final visible parent map after the BFS. The goal of this PR is to determine whether this is the case through a perf try run. The change itself works around the Unord* APIs, but might be worth it to work around the perf regression.
2 parents fdda4c6 + d577cbc commit 4f47a16

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::any::Any;
22
use std::mem;
33
use std::sync::Arc;
44

5-
use rustc_data_structures::unord::ExtendUnord;
5+
use rustc_data_structures::fx::FxHashMap;
66
use rustc_hir::attrs::Deprecation;
77
use rustc_hir::def::{CtorKind, DefKind};
88
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE};
@@ -473,7 +473,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
473473
// the former.
474474
// This is a rudimentary check that does not catch all cases,
475475
// just the easiest.
476-
let mut fallback_map: DefIdMap<DefId> = Default::default();
476+
let mut fallback_map: FxHashMap<DefId, DefId> = Default::default();
477477

478478
// Issue 46112: We want the map to prefer the shortest
479479
// paths when reporting the path to an item. Therefore we
@@ -574,10 +574,16 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
574574
// We must extend the fallback map with items from the visible parent map
575575
// as the extend call overrides existing entries from the latter map,
576576
// which we prefer over fallback entries.
577-
let mut merged_visible_parent_map = fallback_map;
578-
merged_visible_parent_map.extend_unord(visible_parent_map.into_items());
577+
// FIXME: The Unord* APIs lack an efficient way of merging
578+
// the values of one map for only the missing keys of the other map,
579+
// which is required to merge the fallback map into the visible parent map.
580+
// In the meantime, use an "ordered" map internally for fallback entries.
581+
#[allow(rustc::potential_query_instability)]
582+
for (child, parent) in fallback_map {
583+
visible_parent_map.entry(child).or_insert(parent);
584+
}
579585

580-
merged_visible_parent_map
586+
visible_parent_map
581587
},
582588

583589
dependency_formats: |tcx, ()| Arc::new(crate::dependency_format::calculate(tcx)),

0 commit comments

Comments
 (0)