Skip to content

Commit

Permalink
perf: exports info hash (#5125)
Browse files Browse the repository at this point in the history
* perf: exports info hash

* chore: lint

* rewrite hash strategy

* chore: 🤖 lint
  • Loading branch information
IWANABETHATGUY authored Dec 27, 2023
1 parent 610856f commit d148da8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
21 changes: 15 additions & 6 deletions crates/rspack_core/src/exports_info.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/rspack_core/src/module_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub struct ModuleGraph {
connections_map: HashMap<ModuleGraphConnection, ConnectionId>,

pub import_var_map: DashMap<ModuleIdentifier, ImportVarMap>,
pub exports_info_hash: DashMap<ExportsInfoId, u64>,
pub exports_info_map: HashMap<ExportsInfoId, ExportsInfo>,
pub export_info_map: HashMap<ExportInfoId, ExportInfo>,
connection_to_condition: HashMap<ModuleGraphConnection, DependencyCondition>,
Expand Down

0 comments on commit d148da8

Please sign in to comment.