Skip to content

Commit ebb821f

Browse files
committed
Auto merge of rust-lang#119265 - Mark-Simulacrum:remove-cache, r=cjgillot
Remove metadata decoding DefPathHash cache My expectation is that this cache is largely useless. Decoding a DefPathHash from metadata is essentially a pair of memory loads - there's no heavyweight processing involved. Caching it behind a HashMap just adds extra cost and incurs hashing overheads for the indices. Based on rust-lang#119238.
2 parents 08cc634 + f098f34 commit ebb821f

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+8-22
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ pub(crate) struct CrateMetadata {
8888
alloc_decoding_state: AllocDecodingState,
8989
/// Caches decoded `DefKey`s.
9090
def_key_cache: Lock<FxHashMap<DefIndex, DefKey>>,
91-
/// Caches decoded `DefPathHash`es.
92-
def_path_hash_cache: Lock<FxHashMap<DefIndex, DefPathHash>>,
9391

9492
// --- Other significant crate properties ---
9593
/// ID of this crate, from the current compilation session's point of view.
@@ -1485,27 +1483,16 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
14851483
DefPath::make(self.cnum, id, |parent| self.def_key(parent))
14861484
}
14871485

1488-
fn def_path_hash_unlocked(
1489-
self,
1490-
index: DefIndex,
1491-
def_path_hashes: &mut FxHashMap<DefIndex, DefPathHash>,
1492-
) -> DefPathHash {
1493-
*def_path_hashes.entry(index).or_insert_with(|| {
1494-
// This is a hack to workaround the fact that we can't easily encode/decode a Hash64
1495-
// into the FixedSizeEncoding, as Hash64 lacks a Default impl. A future refactor to
1496-
// relax the Default restriction will likely fix this.
1497-
let fingerprint = Fingerprint::new(
1498-
self.root.stable_crate_id.as_u64(),
1499-
self.root.tables.def_path_hashes.get(self, index),
1500-
);
1501-
DefPathHash::new(self.root.stable_crate_id, fingerprint.split().1)
1502-
})
1503-
}
1504-
15051486
#[inline]
15061487
fn def_path_hash(self, index: DefIndex) -> DefPathHash {
1507-
let mut def_path_hashes = self.def_path_hash_cache.lock();
1508-
self.def_path_hash_unlocked(index, &mut def_path_hashes)
1488+
// This is a hack to workaround the fact that we can't easily encode/decode a Hash64
1489+
// into the FixedSizeEncoding, as Hash64 lacks a Default impl. A future refactor to
1490+
// relax the Default restriction will likely fix this.
1491+
let fingerprint = Fingerprint::new(
1492+
self.root.stable_crate_id.as_u64(),
1493+
self.root.tables.def_path_hashes.get(self, index),
1494+
);
1495+
DefPathHash::new(self.root.stable_crate_id, fingerprint.split().1)
15091496
}
15101497

15111498
#[inline]
@@ -1832,7 +1819,6 @@ impl CrateMetadata {
18321819
extern_crate: Lock::new(None),
18331820
hygiene_context: Default::default(),
18341821
def_key_cache: Default::default(),
1835-
def_path_hash_cache: Default::default(),
18361822
};
18371823

18381824
// Need `CrateMetadataRef` to decode `DefId`s in simplified types.

0 commit comments

Comments
 (0)