about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2023-12-23 10:37:05 -0500
committerMark Rousskov <mark.simulacrum@gmail.com>2023-12-23 14:22:36 -0500
commitf098f346ec3b925ad10858fbc6d9e98e15d7ebf1 (patch)
treeff247f9a1420b2c02e14a75f50e142206788a7a5
parent6630d690859d882b2528a39317a701da64fe1203 (diff)
downloadrust-f098f346ec3b925ad10858fbc6d9e98e15d7ebf1.tar.gz
rust-f098f346ec3b925ad10858fbc6d9e98e15d7ebf1.zip
Remove metadata decoding DefPathHash cache
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.
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder.rs30
1 files changed, 8 insertions, 22 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs
index b5e251f3c59..b6fe93759ee 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder.rs
@@ -88,8 +88,6 @@ pub(crate) struct CrateMetadata {
     alloc_decoding_state: AllocDecodingState,
     /// Caches decoded `DefKey`s.
     def_key_cache: Lock<FxHashMap<DefIndex, DefKey>>,
-    /// Caches decoded `DefPathHash`es.
-    def_path_hash_cache: Lock<FxHashMap<DefIndex, DefPathHash>>,
 
     // --- Other significant crate properties ---
     /// ID of this crate, from the current compilation session's point of view.
@@ -1485,27 +1483,16 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
         DefPath::make(self.cnum, id, |parent| self.def_key(parent))
     }
 
-    fn def_path_hash_unlocked(
-        self,
-        index: DefIndex,
-        def_path_hashes: &mut FxHashMap<DefIndex, DefPathHash>,
-    ) -> DefPathHash {
-        *def_path_hashes.entry(index).or_insert_with(|| {
-            // This is a hack to workaround the fact that we can't easily encode/decode a Hash64
-            // into the FixedSizeEncoding, as Hash64 lacks a Default impl. A future refactor to
-            // relax the Default restriction will likely fix this.
-            let fingerprint = Fingerprint::new(
-                self.root.stable_crate_id.as_u64(),
-                self.root.tables.def_path_hashes.get(self, index),
-            );
-            DefPathHash::new(self.root.stable_crate_id, fingerprint.split().1)
-        })
-    }
-
     #[inline]
     fn def_path_hash(self, index: DefIndex) -> DefPathHash {
-        let mut def_path_hashes = self.def_path_hash_cache.lock();
-        self.def_path_hash_unlocked(index, &mut def_path_hashes)
+        // This is a hack to workaround the fact that we can't easily encode/decode a Hash64
+        // into the FixedSizeEncoding, as Hash64 lacks a Default impl. A future refactor to
+        // relax the Default restriction will likely fix this.
+        let fingerprint = Fingerprint::new(
+            self.root.stable_crate_id.as_u64(),
+            self.root.tables.def_path_hashes.get(self, index),
+        );
+        DefPathHash::new(self.root.stable_crate_id, fingerprint.split().1)
     }
 
     #[inline]
@@ -1832,7 +1819,6 @@ impl CrateMetadata {
             extern_crate: Lock::new(None),
             hygiene_context: Default::default(),
             def_key_cache: Default::default(),
-            def_path_hash_cache: Default::default(),
         };
 
         // Need `CrateMetadataRef` to decode `DefId`s in simplified types.