Skip to content

Commit

Permalink
fix: should recalculate order indices in outdated entrypoint (#8970)
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng authored Jan 8, 2025
1 parent 626ac8d commit 6c9d26e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
58 changes: 41 additions & 17 deletions crates/rspack_core/src/build_chunk_graph/code_splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,32 +813,56 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
chunk_group.next_pre_order_index = 0;
chunk_group.next_post_order_index = 0;

let chunk_group = compilation
.chunk_group_by_ukey
.expect_get(&chunk_group_ukey);

let module_graph = compilation.get_module_graph();
let Some(blocks) = self.blocks_by_cgi.get(&cgi.ukey) else {
continue;
};

let mut blocks = blocks.iter().copied().collect::<Vec<_>>();
blocks.sort_unstable();
let Some(DependenciesBlockIdentifier::AsyncDependenciesBlock(block)) =
blocks.first().copied()
else {
continue;
let roots = if let Some(blocks) = self.blocks_by_cgi.get(&cgi.ukey) {
let mut blocks = blocks.iter().copied().collect::<Vec<_>>();
blocks.sort_unstable();

// if one chunk group has multiple blocks, the modules order indices are very likely incorrect
// in every block. For example:
// one chunk import 'a' first then import 'b', while in other chunk import 'b' first then import 'a'.
// User use webpackChunkName to merge these 2 chunks, the `a` and `b` will be in the same chunk, their
// orders cannot be determined.
// Only use the first block to calculate the order indices.
let Some(DependenciesBlockIdentifier::AsyncDependenciesBlock(block)) =
blocks.first().copied()
else {
continue;
};

let Some(block) = module_graph.block_by_id(&block) else {
continue;
};
let root_modules = block
.get_dependencies()
.iter()
.filter_map(|dep| module_graph.module_identifier_by_dependency_id(dep))
.copied()
.collect::<Vec<_>>();

Some(root_modules)
} else if chunk_group.kind.is_entrypoint() && chunk_group.is_initial() {
let entry_chunk_ukey = chunk_group.get_entry_point_chunk();
let entry_modules = compilation
.chunk_graph
.get_chunk_entry_modules(&entry_chunk_ukey);
Some(entry_modules)
} else {
None
};

let Some(block) = module_graph.block_by_id(&block) else {
let Some(roots) = roots else {
continue;
};
let blocks = block
.get_dependencies()
.iter()
.filter_map(|dep| module_graph.module_identifier_by_dependency_id(dep))
.copied()
.collect::<Vec<_>>();

let mut visited = IdentifierIndexSet::default();

for root in blocks {
for root in roots {
let mut ctx = (0, 0, Default::default());
self.calculate_order_index(root, &runtime, &mut visited, &mut ctx, compilation);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.styleB {
background: blue;
}

.styleA {
background: red;
}

.styleB {
background: blue;
}

2 comments on commit 6c9d26e

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 6c9d26e Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2025-01-08 0dbc9ac) Current Change
10000_big_production-mode_disable-minimize + exec 37.8 s ± 463 ms 38.4 s ± 759 ms +1.81 %
10000_development-mode + exec 1.86 s ± 18 ms 1.84 s ± 37 ms -1.03 %
10000_development-mode_hmr + exec 675 ms ± 5.4 ms 671 ms ± 8.2 ms -0.48 %
10000_production-mode + exec 2.5 s ± 38 ms 2.37 s ± 89 ms -5.22 %
arco-pro_development-mode + exec 1.78 s ± 148 ms 1.78 s ± 60 ms +0.12 %
arco-pro_development-mode_hmr + exec 376 ms ± 0.77 ms 377 ms ± 0.42 ms +0.16 %
arco-pro_production-mode + exec 3.63 s ± 72 ms 3.6 s ± 48 ms -0.89 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.65 s ± 113 ms 3.69 s ± 88 ms +1.19 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.6 s ± 53 ms 3.63 s ± 78 ms +0.82 %
large-dyn-imports_development-mode + exec 2.08 s ± 16 ms 2.08 s ± 21 ms -0.15 %
large-dyn-imports_production-mode + exec 2.11 s ± 41 ms 2.1 s ± 26 ms -0.68 %
threejs_development-mode_10x + exec 1.5 s ± 20 ms 1.49 s ± 36 ms -0.44 %
threejs_development-mode_10x_hmr + exec 779 ms ± 27 ms 773 ms ± 19 ms -0.79 %
threejs_production-mode_10x + exec 5.32 s ± 29 ms 5.31 s ± 34 ms -0.31 %
10000_big_production-mode_disable-minimize + rss memory 9502 MiB ± 255 MiB 9630 MiB ± 204 MiB +1.34 %
10000_development-mode + rss memory 642 MiB ± 7.83 MiB 711 MiB ± 14.7 MiB +10.64 %
10000_development-mode_hmr + rss memory 1398 MiB ± 340 MiB 1522 MiB ± 357 MiB +8.84 %
10000_production-mode + rss memory 626 MiB ± 26.9 MiB 739 MiB ± 38.5 MiB +18.01 %
arco-pro_development-mode + rss memory 586 MiB ± 36.2 MiB 633 MiB ± 21.8 MiB +8.04 %
arco-pro_development-mode_hmr + rss memory 617 MiB ± 18.3 MiB 671 MiB ± 32.2 MiB +8.76 %
arco-pro_production-mode + rss memory 735 MiB ± 36.7 MiB 779 MiB ± 46.3 MiB +5.91 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 751 MiB ± 86.5 MiB 779 MiB ± 51.8 MiB +3.65 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 738 MiB ± 41.8 MiB 784 MiB ± 43.2 MiB +6.35 %
large-dyn-imports_development-mode + rss memory 666 MiB ± 12.4 MiB 679 MiB ± 8.06 MiB +1.83 %
large-dyn-imports_production-mode + rss memory 559 MiB ± 9 MiB 591 MiB ± 4.23 MiB +5.81 %
threejs_development-mode_10x + rss memory 637 MiB ± 33.9 MiB 681 MiB ± 33.6 MiB +6.81 %
threejs_development-mode_10x_hmr + rss memory 1103 MiB ± 187 MiB 1205 MiB ± 224 MiB +9.26 %
threejs_production-mode_10x + rss memory 918 MiB ± 47 MiB 981 MiB ± 39.3 MiB +6.85 %

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 6c9d26e Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ecosystem CI detail: Open

suite result
modernjs ❌ failure
rspress ✅ success
rslib ✅ success
rsbuild ✅ success
rsdoctor ✅ success
examples ✅ success
devserver ✅ success
nuxt ✅ success

Please sign in to comment.