Skip to content

Commit

Permalink
fix: remove dynamic entry should re-build chunk graph (#9425)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk authored Feb 21, 2025
1 parent fab381d commit 5577719
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 12 deletions.
49 changes: 38 additions & 11 deletions crates/rspack_core/src/build_chunk_graph/incremental.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::{collections::HashSet, hash::BuildHasherDefault};

use num_bigint::BigUint;
use rspack_collections::{IdentifierHasher, IdentifierIndexSet, IdentifierMap, UkeySet};
use rspack_collections::{
IdentifierHasher, IdentifierIndexSet, IdentifierMap, IdentifierSet, UkeySet,
};
use rspack_error::Result;
use tracing::instrument;

Expand Down Expand Up @@ -443,26 +445,51 @@ impl CodeSplitter {
self.stat_cache_miss_by_available_modules = 0;
self.stat_cache_miss_by_cant_rebuild = 0;

let modules = if let Some(mutations) = compilation
let (affected_modules, removed_modules) = if let Some(mutations) = compilation
.incremental
.mutations_read(IncrementalPasses::BUILD_CHUNK_GRAPH)
{
mutations.get_affected_modules_with_module_graph(&module_graph)
let affected_modules = mutations.get_affected_modules_with_module_graph(&module_graph);
let removed_modules: IdentifierSet = mutations
.iter()
.filter_map(|mutation| match mutation {
Mutation::ModuleRemove { module } => Some(*module),
_ => None,
})
.collect();
(affected_modules, removed_modules)
} else {
compilation
.get_module_graph()
.modules()
.keys()
.copied()
.collect()
(
compilation
.get_module_graph()
.modules()
.keys()
.copied()
.collect(),
Default::default(),
)
};

let mut edges = vec![];

// collect invalidate caches before we do anything to the chunk graph
let dirty_blocks = self.collect_dirty_caches(compilation, modules.iter().copied());
let dirty_blocks = self.collect_dirty_caches(
compilation,
affected_modules
.iter()
.chain(removed_modules.iter())
.copied(),
);

for m in removed_modules {
for module_map in self.block_modules_runtime_map.values_mut() {
module_map.swap_remove(&DependenciesBlockIdentifier::Module(m));
}

for m in modules {
self.invalidate_from_module(m, compilation)?;
}

for m in affected_modules {
for module_map in self.block_modules_runtime_map.values_mut() {
module_map.swap_remove(&DependenciesBlockIdentifier::Module(m));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ impl HasModuleGraphChange {
if self.disabled {
return;
}
if artifact.built_modules.len() != self.expect_built_modules_len {
if artifact.built_modules.len() != self.expect_built_modules_len
|| artifact.built_modules.len() != artifact.revoked_modules.len()
{
// contain unexpected module built
artifact.has_module_graph_change = true;
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
it("should have correct entrypoints", function() {
expect(Object.keys(__STATS__.entrypoints)).toEqual(["bundle0", "bundle1"]);

const index0 = __STATS__.modules.find(m => m.name === "./index0.js");
expect(index0.built).toBe(true);
expect(index0.reasons.length).toBe(1);
expect(index0.reasons[0].type).toBe("entry");

const index1 = __STATS__.modules.find(m => m.name === "./index1.js");
expect(index1.built).toBe(true);
expect(index1.reasons.length).toBe(1);
expect(index1.reasons[0].type).toBe("entry");
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log.bind(console, 1);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
it("should have correct entrypoints", function() {
expect(Object.keys(__STATS__.entrypoints)).toEqual(["bundle0"]);

const index0 = __STATS__.modules.find(m => m.name === "./index0.js");
expect(index0.built).toBe(true);
expect(index0.reasons.length).toBe(1);
expect(index0.reasons[0].type).toBe("entry");
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const path = require("path");
const fs = require("fs");

let compiler;
let step = 0;
let entries;

/** @type {import("@rspack/core").Configuration} */
module.exports = {
entry: async () => {
const context = compiler.context;
if (step === 0) {
const files = await fs.promises.readdir(context);
entries = files.filter(f => f.startsWith("index"));
entries.sort();
} else if (step === 1) {
entries.pop();
} else {
throw new Error(`unreachable step: ${step}`);
}
return entries.reduce((acc, e, i) => {
acc[`bundle${i}`] = path.resolve(context, e);
return acc;
}, {});
},
output: {
filename: "[name].js"
},
plugins: [
function (c) {
compiler = c;
c.hooks.done.tap("test", () => {
step += 1;
});
}
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
findBundle(i) {
return ["bundle0.js"];
}
};

2 comments on commit 5577719

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 5577719 Feb 21, 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 ❌ failure
rsdoctor ❌ failure
examples ✅ success
devserver ✅ success
nuxt ✅ success

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 5577719 Feb 21, 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-02-21 18420bb) Current Change
10000_big_production-mode_disable-minimize + exec 36.6 s ± 380 ms 37.4 s ± 1.06 s +2.10 %
10000_development-mode + exec 1.71 s ± 14 ms 1.69 s ± 17 ms -1.17 %
10000_development-mode_hmr + exec 671 ms ± 13 ms 668 ms ± 34 ms -0.40 %
10000_production-mode + exec 2.19 s ± 56 ms 2.16 s ± 60 ms -1.11 %
10000_production-mode_persistent-cold + exec 2.35 s ± 128 ms 2.28 s ± 39 ms -3.03 %
10000_production-mode_persistent-hot + exec 1.62 s ± 28 ms 1.7 s ± 316 ms +5.15 %
arco-pro_development-mode + exec 1.72 s ± 92 ms 1.74 s ± 101 ms +1.29 %
arco-pro_development-mode_hmr + exec 374 ms ± 1.2 ms 375 ms ± 1.9 ms +0.18 %
arco-pro_production-mode + exec 3.58 s ± 82 ms 3.5 s ± 175 ms -2.12 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.57 s ± 41 ms 3.61 s ± 220 ms +1.18 %
arco-pro_production-mode_persistent-cold + exec 3.67 s ± 287 ms 3.64 s ± 104 ms -0.63 %
arco-pro_production-mode_persistent-hot + exec 2.24 s ± 106 ms 2.37 s ± 162 ms +5.92 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.54 s ± 225 ms 3.55 s ± 112 ms +0.25 %
large-dyn-imports_development-mode + exec 1.97 s ± 37 ms 1.95 s ± 42 ms -1.14 %
large-dyn-imports_production-mode + exec 2.02 s ± 37 ms 2.03 s ± 134 ms +0.48 %
threejs_development-mode_10x + exec 1.48 s ± 140 ms 1.44 s ± 12 ms -3.14 %
threejs_development-mode_10x_hmr + exec 817 ms ± 22 ms 785 ms ± 28 ms -3.95 %
threejs_production-mode_10x + exec 5.14 s ± 161 ms 5.03 s ± 96 ms -2.08 %
threejs_production-mode_10x_persistent-cold + exec 5.15 s ± 352 ms 5.05 s ± 48 ms -2.06 %
threejs_production-mode_10x_persistent-hot + exec 4.49 s ± 273 ms 4.43 s ± 176 ms -1.30 %
10000_big_production-mode_disable-minimize + rss memory 8682 MiB ± 73.1 MiB 8689 MiB ± 104 MiB +0.09 %
10000_development-mode + rss memory 651 MiB ± 9.54 MiB 680 MiB ± 33.8 MiB +4.38 %
10000_development-mode_hmr + rss memory 1191 MiB ± 187 MiB 1313 MiB ± 178 MiB +10.27 %
10000_production-mode + rss memory 620 MiB ± 27.7 MiB 658 MiB ± 13.5 MiB +6.19 %
10000_production-mode_persistent-cold + rss memory 729 MiB ± 21.8 MiB 767 MiB ± 11.8 MiB +5.13 %
10000_production-mode_persistent-hot + rss memory 703 MiB ± 22.6 MiB 737 MiB ± 39.6 MiB +4.86 %
arco-pro_development-mode + rss memory 574 MiB ± 19.3 MiB 598 MiB ± 21.5 MiB +4.16 %
arco-pro_development-mode_hmr + rss memory 660 MiB ± 46.9 MiB 681 MiB ± 72 MiB +3.19 %
arco-pro_production-mode + rss memory 711 MiB ± 22.3 MiB 732 MiB ± 22.7 MiB +2.93 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 729 MiB ± 38.7 MiB 750 MiB ± 3.73 MiB +2.91 %
arco-pro_production-mode_persistent-cold + rss memory 789 MiB ± 47.8 MiB 805 MiB ± 42 MiB +2.00 %
arco-pro_production-mode_persistent-hot + rss memory 636 MiB ± 24.6 MiB 701 MiB ± 21.8 MiB +10.31 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 725 MiB ± 22.4 MiB 739 MiB ± 31.6 MiB +2.02 %
large-dyn-imports_development-mode + rss memory 644 MiB ± 5.16 MiB 672 MiB ± 12 MiB +4.42 %
large-dyn-imports_production-mode + rss memory 521 MiB ± 5.02 MiB 553 MiB ± 7.81 MiB +6.11 %
threejs_development-mode_10x + rss memory 572 MiB ± 30 MiB 580 MiB ± 20.5 MiB +1.38 %
threejs_development-mode_10x_hmr + rss memory 1128 MiB ± 228 MiB 1186 MiB ± 111 MiB +5.15 %
threejs_production-mode_10x + rss memory 851 MiB ± 78.3 MiB 863 MiB ± 33.8 MiB +1.37 %
threejs_production-mode_10x_persistent-cold + rss memory 957 MiB ± 45.2 MiB 968 MiB ± 49.9 MiB +1.18 %
threejs_production-mode_10x_persistent-hot + rss memory 811 MiB ± 63.4 MiB 829 MiB ± 46 MiB +2.17 %

Threshold exceeded: ["10000_production-mode_persistent-hot + exec","arco-pro_production-mode_persistent-hot + exec"]

Please sign in to comment.