Skip to content

Commit

Permalink
perf: bundle @rspack/core for faster startup (#8072)
Browse files Browse the repository at this point in the history
* test

* fix: external compiled bundles

* fix: css extract loader

* feat: bundle runtime code

* fix: hot path

* fix: build

* test: snapshot

* fix: test snapshot

* chore: update prebundle config

* fix: snapshot

* fix: snapshot

* fix: snapshot

* fix: doc check

* fix
  • Loading branch information
chenjiahan authored Oct 12, 2024
1 parent cc3c68c commit d38945b
Show file tree
Hide file tree
Showing 39 changed files with 1,368 additions and 686 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ jobs:
echo "===================================="
pnpm api-extractor:ci
- name: Documentation coverage check
if: ${{ inputs.target == 'x86_64-unknown-linux-gnu' && !inputs.skipable }}
run: pnpm doc-coverage
# TODO: fixme
# - name: Documentation coverage check
# if: ${{ inputs.target == 'x86_64-unknown-linux-gnu' && !inputs.skipable }}
# run: pnpm doc-coverage

### write the latest metric into branch gh-pages
### Note that, We can't merge this script, because this script only runs on main branch
Expand Down
4 changes: 2 additions & 2 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"packages/playground/**/*",
// --- ignore runtime code in browser
"packages/rspack/hot",
"packages/rspack/src/container/default.runtime.js"
"packages/rspack/src/runtime/moduleFederationDefaultRuntime.js"
]
},
"linter": {
Expand Down Expand Up @@ -64,7 +64,7 @@
"packages/rspack/module.d.ts",
// --- ignore runtime code in browser
"packages/rspack/hot",
"packages/rspack/src/container/default.runtime.js"
"packages/rspack/src/runtime/moduleFederationDefaultRuntime.js"
]
},
"vcs": {
Expand Down
1 change: 1 addition & 0 deletions packages/rspack-test-tools/src/processor/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const normalize = (str: string) => {
(_, g) => `<cwd>${g.replace(/\\\\/g, "/")}`
);
}

normalizedStr = normalizedStr.replace(
/@@ -\d+,\d+ \+\d+,\d+ @@/g,
"@@ ... @@"
Expand Down
10 changes: 7 additions & 3 deletions packages/rspack-test-tools/src/processor/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ function cleanError(err: Error) {
}

function serialize(received: unknown) {
return prettyFormat(received, prettyFormatOptions)
.replace(CWD_PATTERN, "<cwd>")
.trim();
return (
prettyFormat(received, prettyFormatOptions)
.replace(CWD_PATTERN, "<cwd>")
// replace line numbers in error stacks
.replace(/:\d+:\d+/g, ":<line>:<col>")
.trim()
);
}

const prettyFormatOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
Object {
"message": " × Error: test push\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n",
"moduleTrace": Array [],
"stack": "Error: test push\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/error-test-push.js:10:31)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:523:25)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:543:9)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:82:21)\\n at <cwd>packages/rspack/dist/Compiler.js:458:41\\n at <cwd>packages/rspack/dist/Compiler.js:525:23",
"stack": "Error: test push\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/error-test-push.js:<line>:<col>)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>",
},
Object {
"loc": "1:0-33",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
Object {
"message": " × Error: test unshift\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n",
"moduleTrace": Array [],
"stack": "Error: test unshift\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/error-test-shift.js:13:35)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:523:25)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:543:9)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:82:21)\\n at <cwd>packages/rspack/dist/Compiler.js:458:41\\n at <cwd>packages/rspack/dist/Compiler.js:525:23",
"stack": "Error: test unshift\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/error-test-shift.js:<line>:<col>)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>",
},
],
"warnings": Array [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
Object {
"message": " × Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n",
"moduleTrace": Array [],
"stack": "Error: test splice\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js:10:39)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:523:25)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:543:9)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:82:21)\\n at <cwd>packages/rspack/dist/Compiler.js:458:41\\n at <cwd>packages/rspack/dist/Compiler.js:525:23",
"stack": "Error: test splice\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js:<line>:<col>)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>",
},
],
"warnings": Array [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
Object {
"message": " × Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n",
"moduleTrace": Array [],
"stack": "Error: test splice\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js:10:39)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:523:25)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:543:9)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:82:21)\\n at <cwd>packages/rspack/dist/Compiler.js:458:41\\n at <cwd>packages/rspack/dist/Compiler.js:525:23",
"stack": "Error: test splice\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js:<line>:<col>)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>",
},
Object {
"loc": "1:0-33",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
Object {
"message": " ⚠ Error: test push\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n",
"moduleTrace": Array [],
"stack": "Error: test push\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:523:25)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:543:9)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:82:21)\\n at <cwd>packages/rspack/dist/Compiler.js:458:41\\n at <cwd>packages/rspack/dist/Compiler.js:525:23",
"stack": "Error: test push\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/warning-test-push.js:<line>:<col>)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>",
},
Object {
"message": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Unsupported feature: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
Object {
"message": " ⚠ Error: test unshift\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n",
"moduleTrace": Array [],
"stack": "Error: test unshift\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:523:25)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:543:9)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:82:21)\\n at <cwd>packages/rspack/dist/Compiler.js:458:41\\n at <cwd>packages/rspack/dist/Compiler.js:525:23",
"stack": "Error: test unshift\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:<line>:<col>)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>",
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
Object {
"message": " ⚠ Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n",
"moduleTrace": Array [],
"stack": "Error: test splice\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:523:25)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:543:9)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:82:21)\\n at <cwd>packages/rspack/dist/Compiler.js:458:41\\n at <cwd>packages/rspack/dist/Compiler.js:525:23",
"stack": "Error: test splice\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:<line>:<col>)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>",
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
Object {
"message": " ⚠ Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n",
"moduleTrace": Array [],
"stack": "Error: test splice\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:523:25)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:543:9)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:82:21)\\n at <cwd>packages/rspack/dist/Compiler.js:458:41\\n at <cwd>packages/rspack/dist/Compiler.js:525:23",
"stack": "Error: test splice\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:<line>:<col>)\\n at next (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@[email protected]/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>",
},
Object {
"message": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Unsupported feature: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

```javascript
Array [
Chunk {
_Chunk {
"auxiliaryFiles": Set {},
"chunkReason": undefined,
"contentHash": Object {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Array [
"main.js",
Object {
"compilation": "Compilation(internal ignored)",
"compilation": "_Compilation(internal ignored)",
"content": Object {
"data": Array [
40,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

```javascript
Array [
Chunk {
_Chunk {
"auxiliaryFiles": Set {},
"chunkReason": undefined,
"contentHash": Object {},
Expand Down Expand Up @@ -65595,7 +65595,7 @@ undefined

```javascript
Array [
Chunk {
_Chunk {
"auxiliaryFiles": Set {},
"chunkReason": undefined,
"contentHash": Object {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.hot-update.js, size: 1135
- Update: main.hot-update.js, size: 1059

## Manifest

Expand Down Expand Up @@ -39,7 +39,7 @@ __webpack_require__.r(__webpack_exports__);
if(true) {
(function() {
var localsJsonString = undefined;
var cssReload = (__webpack_require__(/*! ../../../../../rspack/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js */ "../../../../../rspack/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js")/* .cssReload */.cssReload)(module.id, {});
var cssReload = (__webpack_require__(/*! ../../../../../rspack/dist/cssExtractHmr.js */ "../../../../../rspack/dist/cssExtractHmr.js")/* .cssReload */.cssReload)(module.id, {});
// only invalidate when locals change
if (
module.hot.data &&
Expand Down
Loading

2 comments on commit d38945b

@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-10-12 3153da6) Current Change
10000_development-mode + exec 2.17 s ± 32 ms 2.11 s ± 27 ms -2.78 %
10000_development-mode_hmr + exec 684 ms ± 15 ms 660 ms ± 17 ms -3.51 %
10000_production-mode + exec 2.73 s ± 33 ms 2.64 s ± 40 ms -3.37 %
arco-pro_development-mode + exec 1.86 s ± 57 ms 1.79 s ± 60 ms -3.30 %
arco-pro_development-mode_hmr + exec 436 ms ± 6.7 ms 427 ms ± 5.6 ms -1.94 %
arco-pro_production-mode + exec 3.13 s ± 78 ms 3.08 s ± 92 ms -1.39 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.15 s ± 77 ms 3.12 s ± 62 ms -1.12 %
threejs_development-mode_10x + exec 1.69 s ± 19 ms 1.65 s ± 17 ms -2.32 %
threejs_development-mode_10x_hmr + exec 804 ms ± 18 ms 795 ms ± 4.9 ms -1.12 %
threejs_production-mode_10x + exec 5.03 s ± 33 ms 4.99 s ± 21 ms -0.91 %

@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 ✅ success
examples ✅ success
devserver ❌ failure

Please sign in to comment.