diff --git a/crates/rspack_core/src/exports_info.rs b/crates/rspack_core/src/exports_info.rs index afc2951c31f..bc7436d1fb5 100644 --- a/crates/rspack_core/src/exports_info.rs +++ b/crates/rspack_core/src/exports_info.rs @@ -1,3 +1,4 @@ +use std::collections::hash_map::DefaultHasher; use std::collections::hash_map::Entry; use std::hash::Hasher; use std::sync::atomic::AtomicU32; @@ -435,21 +436,29 @@ pub struct ExportsInfo { impl ExportsHash for ExportsInfo { fn export_info_hash(&self, hasher: &mut dyn Hasher, module_graph: &ModuleGraph) { + if let Some(hash) = module_graph.exports_info_hash.get(&self.id) { + hash.dyn_hash(hasher); + return; + }; + let mut default_hash = DefaultHasher::default(); for (name, export_info_id) in &self.exports { - name.dyn_hash(hasher); - export_info_id.export_info_hash(hasher, module_graph); + name.dyn_hash(&mut default_hash); + export_info_id.export_info_hash(&mut default_hash, module_graph); } self .other_exports_info - .export_info_hash(hasher, module_graph); + .export_info_hash(&mut default_hash, module_graph); self ._side_effects_only_info - .export_info_hash(hasher, module_graph); - self._exports_are_ordered.dyn_hash(hasher); + .export_info_hash(&mut default_hash, module_graph); + self._exports_are_ordered.dyn_hash(&mut default_hash); if let Some(redirect_to) = self.redirect_to { - redirect_to.export_info_hash(hasher, module_graph); + redirect_to.export_info_hash(&mut default_hash, module_graph); } + let hash = default_hash.finish(); + module_graph.exports_info_hash.insert(self.id, hash); + hash.dyn_hash(hasher); } } diff --git a/crates/rspack_core/src/module_graph/mod.rs b/crates/rspack_core/src/module_graph/mod.rs index 3ac88ebfc39..a905a369b30 100644 --- a/crates/rspack_core/src/module_graph/mod.rs +++ b/crates/rspack_core/src/module_graph/mod.rs @@ -60,6 +60,7 @@ pub struct ModuleGraph { connections_map: HashMap, pub import_var_map: DashMap, + pub exports_info_hash: DashMap, pub exports_info_map: HashMap, pub export_info_map: HashMap, connection_to_condition: HashMap,