Skip to content

Commit

Permalink
fix: output should be consistent when using splitChunks (#8425)
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng authored Nov 13, 2024
1 parent 78aa2e0 commit 7c9e9f8
Show file tree
Hide file tree
Showing 13 changed files with 12,455 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/rspack_plugin_split_chunks/src/plugin/max_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use regex::Regex;
use rspack_collections::{DatabaseItem, UkeyMap};
use rspack_core::incremental::Mutation;
use rspack_core::{
ChunkUkey, Compilation, CompilerOptions, Module, ModuleIdentifier, DEFAULT_DELIMITER,
compare_modules_by_identifier, ChunkUkey, Compilation, CompilerOptions, Module, ModuleIdentifier,
DEFAULT_DELIMITER,
};
use rspack_error::Result;
use rspack_hash::{RspackHash, RspackHashDigest};
Expand Down Expand Up @@ -83,10 +84,12 @@ fn deterministic_grouping_for_modules(
) -> Vec<Group> {
let mut results: Vec<Group> = Default::default();
let module_graph = compilation.get_module_graph();
let items = compilation
let mut items = compilation
.chunk_graph
.get_chunk_modules(chunk, &module_graph);

items.sort_unstable_by(|a, b| compare_modules_by_identifier(a, b));

let context = compilation.options.context.as_ref();

let nodes = items.into_iter().map(|module| {
Expand Down Expand Up @@ -183,6 +186,7 @@ fn deterministic_grouping_for_modules(
if left <= right {
let right_nodes = group.nodes.split_off(left);
let left_nodes = group.nodes;

queue.push(Group::new(right_nodes, None));
queue.push(Group::new(left_nodes, None));
}
Expand Down
45 changes: 45 additions & 0 deletions packages/rspack-test-tools/tests/compilerCases/consistent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const stats = [];

/** @type {import('../../dist').TCompilerCaseConfig} */
module.exports = {
description: "should be called every compilation",
options(context) {
return {
context: context.getSource(),
entry: "./split-chunks/src/index.js",
optimization: {
splitChunks: {
chunks: 'all',
minSize: 100 * 1024,
maxSize: 200 * 1024,
}
},
stats: {
assets: true
}
};
},
async build(_, compiler) {
await new Promise(resolve => {
compiler.run((err, stat) => {
if (err) {
throw err
}
stats.push(stat.toJson().assets)
compiler.run((_, stat) => {
stats.push(stat.toJson().assets)
compiler.run((_, stat) => {
stats.push(stat.toJson().assets)
resolve();
});
});
});
});
},
async check() {
const stats1 = stats[0].reduce((acc, curr) => acc + curr.name, '')
const stats2 = stats[1].reduce((acc, curr) => acc + curr.name, '')
const stats3 = stats[2].reduce((acc, curr) => acc + curr.name, '')
expect(stats1 === stats2 === stats3);
}
};
5,811 changes: 5,811 additions & 0 deletions packages/rspack-test-tools/tests/fixtures/split-chunks/src/400k.js

Large diffs are not rendered by default.

726 changes: 726 additions & 0 deletions packages/rspack-test-tools/tests/fixtures/split-chunks/src/50k-1.js

Large diffs are not rendered by default.

726 changes: 726 additions & 0 deletions packages/rspack-test-tools/tests/fixtures/split-chunks/src/50k-2.js

Large diffs are not rendered by default.

726 changes: 726 additions & 0 deletions packages/rspack-test-tools/tests/fixtures/split-chunks/src/50k-3.js

Large diffs are not rendered by default.

726 changes: 726 additions & 0 deletions packages/rspack-test-tools/tests/fixtures/split-chunks/src/50k-4.js

Large diffs are not rendered by default.

726 changes: 726 additions & 0 deletions packages/rspack-test-tools/tests/fixtures/split-chunks/src/50k-5.js

Large diffs are not rendered by default.

726 changes: 726 additions & 0 deletions packages/rspack-test-tools/tests/fixtures/split-chunks/src/50k-6.js

Large diffs are not rendered by default.

726 changes: 726 additions & 0 deletions packages/rspack-test-tools/tests/fixtures/split-chunks/src/50k-7.js

Large diffs are not rendered by default.

726 changes: 726 additions & 0 deletions packages/rspack-test-tools/tests/fixtures/split-chunks/src/50k-8.js

Large diffs are not rendered by default.

726 changes: 726 additions & 0 deletions packages/rspack-test-tools/tests/fixtures/split-chunks/src/50k.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { createElement } from "react";
import { render } from "react-dom";
import { fiftyK } from "./50k";
import { fiftyK as fiftyK_1 } from "./50k-1";
import { fiftyK as fiftyK_2 } from "./50k-2";
import { fiftyK as fiftyK_3 } from "./50k-3";
import { fiftyK as fiftyK_4 } from "./50k-4";
import { fiftyK as fiftyK_5 } from "./50k-5";
import { fiftyK as fiftyK_6 } from "./50k-6";
import { fiftyK as fiftyK_7 } from "./50k-7";
import { fiftyK as fiftyK_8 } from "./50k-8";

import {
fiftyK1,
fiftyK2,
fiftyK3,
fiftyK4,
fiftyK5,
fiftyK6,
fiftyK7,
fiftyK8,
} from "./400k";

import axios from "axios";
import dayjs from "dayjs";
import * as ReactUse from "react-use";
import * as ahooks from "ahooks";

window.lib = {
axios,
dayjs,
ReactUse,
ahooks,
fiftyK,
fiftyK1,
fiftyK2,
fiftyK3,
fiftyK4,
fiftyK5,
fiftyK6,
fiftyK7,
fiftyK8,
fiftyK_1,
fiftyK_2,
fiftyK_3,
fiftyK_4,
fiftyK_5,
fiftyK_6,
fiftyK_7,
fiftyK_8,
};

render(
createElement("div", null, [
createElement("h1", null, `Hello World ${__BUNDLE__}`),
createElement("p", null, "see more detail in devtool/network"),
]),
document.getElementById("root")
);

2 comments on commit 7c9e9f8

@rspack-bot
Copy link

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 (2024-11-13 0e01f8c) Current Change
10000_big_production-mode + exec 44.9 s ± 1.17 s 44.3 s ± 838 ms -1.35 %
10000_development-mode + exec 1.81 s ± 45 ms 1.8 s ± 41 ms -0.48 %
10000_development-mode_hmr + exec 644 ms ± 7.8 ms 642 ms ± 6.2 ms -0.28 %
10000_production-mode + exec 2.43 s ± 49 ms 2.43 s ± 30 ms 0.00 %
arco-pro_development-mode + exec 1.77 s ± 77 ms 1.77 s ± 69 ms -0.34 %
arco-pro_development-mode_hmr + exec 431 ms ± 2 ms 430 ms ± 2.6 ms -0.18 %
arco-pro_production-mode + exec 3.17 s ± 70 ms 3.17 s ± 82 ms -0.02 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.23 s ± 79 ms 3.18 s ± 68 ms -1.48 %
threejs_development-mode_10x + exec 1.58 s ± 15 ms 1.58 s ± 10 ms +0.03 %
threejs_development-mode_10x_hmr + exec 778 ms ± 6.8 ms 772 ms ± 11 ms -0.75 %
threejs_production-mode_10x + exec 4.95 s ± 35 ms 4.96 s ± 27 ms +0.19 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Ran ecosystem CI: Open

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

Please sign in to comment.