Skip to content

Commit 1f8587b

Browse files
authored
perf: parallelize getting full module names in the deterministic module ids plugin (#10906)
perf: parallel getting full module names in deterministic module ids plugin
1 parent 123e4f5 commit 1f8587b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

crates/rspack_ids/src/deterministic_module_ids_plugin.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use rayon::prelude::*;
2+
use rspack_collections::IdentifierMap;
13
use rspack_core::{
24
incremental::IncrementalPasses, ApplyContext, ChunkGraph, Compilation, CompilationModuleIds,
35
CompilerOptions, Plugin, PluginContext,
@@ -43,9 +45,20 @@ async fn module_ids(&self, compilation: &mut Compilation) -> Result<()> {
4345
.filter_map(|i| module_graph.module_by_identifier(&i))
4446
.collect::<Vec<_>>();
4547
let used_ids_len = used_ids.len();
48+
49+
let module_names = modules
50+
.par_iter()
51+
.map(|m| (m.identifier(), get_full_module_name(m, context)))
52+
.collect::<IdentifierMap<String>>();
53+
4654
assign_deterministic_ids(
4755
modules,
48-
|m| get_full_module_name(m, context),
56+
|m| {
57+
module_names
58+
.get(&m.identifier())
59+
.expect("should have generated full module name")
60+
.to_string()
61+
},
4962
|a, b| compare_modules_by_pre_order_index_or_identifier(&module_graph, a, b),
5063
|module, id| {
5164
if !used_ids.insert(id.to_string()) {

0 commit comments

Comments
 (0)