Skip to content

Commit b36069e

Browse files
authored
perf: improve concatenated plugin (#11434)
1 parent f275498 commit b36069e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ impl ModuleConcatenationPlugin {
190190

191191
let mut set = IdentifierIndexSet::default();
192192
for (con, (has_imported_names, cached_active)) in &cached.connections {
193+
if set.contains(con.module_identifier()) {
194+
continue;
195+
}
196+
193197
let is_target_active = if let Some(runtime) = runtime {
194198
if cached.runtime == *runtime {
195199
// runtime is same, use cached value
@@ -374,20 +378,25 @@ impl ModuleConcatenationPlugin {
374378
let mut incoming_connections_from_modules = HashMap::default();
375379
for (origin_module, connections) in incomings.iter() {
376380
if let Some(origin_module) = origin_module {
377-
if chunk_graph.get_number_of_module_chunks(*origin_module) == 0 {
381+
let number_of_chunks = module_cache
382+
.get(origin_module)
383+
.map(|m| m.number_of_chunks)
384+
.unwrap_or_else(|| chunk_graph.get_number_of_module_chunks(*origin_module));
385+
386+
if number_of_chunks == 0 {
378387
// Ignore connection from orphan modules
379388
continue;
380389
}
381390

382391
let is_intersect = if let Some(runtime) = runtime {
383392
if let Some(origin_runtime) = module_cache.get(origin_module).map(|m| &m.runtime) {
384-
runtime.intersection(origin_runtime).count() > 0
393+
!runtime.is_disjoint(origin_runtime)
385394
} else {
386395
let mut origin_runtime = RuntimeSpec::default();
387396
for r in chunk_graph.get_module_runtimes_iter(*origin_module, chunk_by_ukey) {
388397
origin_runtime.extend(r);
389398
}
390-
runtime.intersection(&origin_runtime).count() > 0
399+
!runtime.is_disjoint(&origin_runtime)
391400
}
392401
} else {
393402
false
@@ -1068,6 +1077,9 @@ impl ModuleConcatenationPlugin {
10681077
connection.is_active(&module_graph, Some(&runtime), module_graph_cache),
10691078
);
10701079
}
1080+
let number_of_chunks = compilation
1081+
.chunk_graph
1082+
.get_number_of_module_chunks(*module_id);
10711083
(
10721084
*module_id,
10731085
NoRuntimeModuleCache {
@@ -1076,6 +1088,7 @@ impl ModuleConcatenationPlugin {
10761088
connections,
10771089
incomings,
10781090
active_incomings,
1091+
number_of_chunks,
10791092
},
10801093
)
10811094
})
@@ -1396,6 +1409,7 @@ pub struct NoRuntimeModuleCache {
13961409
connections: Vec<(ModuleGraphConnection, (bool, bool))>,
13971410
incomings: HashMap<Option<ModuleIdentifier>, Vec<ModuleGraphConnection>>,
13981411
active_incomings: HashMap<DependencyId, bool>,
1412+
number_of_chunks: usize,
13991413
}
14001414

14011415
async fn create_concatenated_module(

0 commit comments

Comments
 (0)