Skip to content

Commit 9924a3e

Browse files
perf(module-concat): cache incoming analysis across roots
Cache runtime-dependent incoming module analysis across root searches while keeping root-specific chunk and ESM checks outside the cache. Add runtime-isolation coverage for multi-runtime builds. Co-authored-by: ScriptedAlchemy <zackary.l.jackson@gmail.com>
1 parent 7d3b3d7 commit 9924a3e

8 files changed

Lines changed: 270 additions & 175 deletions

File tree

crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs

Lines changed: 189 additions & 175 deletions
Large diffs are not rendered by default.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { getValue as getRootAValue } from "./root-a";
2+
import { stable } from "./root-shared";
3+
4+
it("should keep runtime-specific concatenation results isolated", () => {
5+
expect(getRootAValue()).toBe(42);
6+
expect(stable).toBe(1);
7+
8+
const rootAGroup = __STATS__.modules.find(module =>
9+
module.modules?.some(nested => nested.name.endsWith("root-a.js"))
10+
);
11+
expect(rootAGroup).toBeDefined();
12+
13+
const shared = __STATS__.modules.find(module => module.name.endsWith("root-shared.js"));
14+
expect(shared).toBeDefined();
15+
const expectedBailout = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK
16+
? "runtime-dependent referenced"
17+
: "not in the same chunk(s)";
18+
expect(shared.optimizationBailout).toEqual(
19+
expect.arrayContaining([expect.stringContaining(expectedBailout)])
20+
);
21+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { getValue } from "./root-shared";
2+
3+
it("should preserve the runtime-dependent export", () => {
4+
expect(getValue()).toBe(42);
5+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export let value = 42;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { value } from "./leaf";
2+
3+
export const getValue = () => value;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { value } from "./leaf";
2+
3+
export const stable = 1;
4+
export const getValue = () => value;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/** @type {import("@rspack/core").Configuration} */
2+
module.exports = {
3+
mode: 'production',
4+
entry: {
5+
a: './a.js',
6+
b: './b.js',
7+
},
8+
output: {
9+
filename: '[name].js',
10+
},
11+
module: {
12+
rules: [
13+
{
14+
test: /\.js$/,
15+
sideEffects: false,
16+
},
17+
],
18+
},
19+
optimization: {
20+
concatenateModules: true,
21+
innerGraph: true,
22+
minimize: false,
23+
sideEffects: true,
24+
splitChunks: {
25+
chunks: 'all',
26+
minSize: 0,
27+
cacheGroups: {
28+
shared: {
29+
enforce: true,
30+
name: 'shared',
31+
test: /root-shared/,
32+
},
33+
},
34+
},
35+
usedExports: true,
36+
},
37+
stats: {
38+
modules: true,
39+
nestedModules: true,
40+
optimizationBailout: true,
41+
},
42+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
findBundle() {
3+
return ["shared.js", "a.js", "b.js"];
4+
},
5+
};

0 commit comments

Comments
 (0)