Skip to content

perf: bundle @rspack/core for faster startup#8072

Merged
chenjiahan merged 17 commits intomainfrom
bundle_core_1008
Oct 12, 2024
Merged

perf: bundle @rspack/core for faster startup#8072
chenjiahan merged 17 commits intomainfrom
bundle_core_1008

Conversation

@chenjiahan
Copy link
Copy Markdown
Member

@chenjiahan chenjiahan commented Oct 9, 2024

Summary

  • This PR uses tsup to bundle @rspack/core, this reduces the number of modules required by Node.js and speeds up Rspack startup time.
  • Move runtime code to src/runtime folder for easier management.
  • Remove some packages from prebundle.config.js because they can be bundled to dist/index.js.
  • Once Rslib is ready, we will switch from tsup to Rslib.

TODO: tests/plugin-test/css-extract/stringifyLocal.test.js and packages/rspack/scripts/check-documentation-coverage.mjs depend on internal dist files and should be fixed in separate PRs.

Comparasion

require('@rspack/core') become 30ms faster:

  • before (65~75ms):
hyperfine --warmup 3 'node ./node_modules/@rsbuild/core/bin/rsbuild.js build'
Benchmark 1: node ./node_modules/@rsbuild/core/bin/rsbuild.js build
  Time (mean ± σ):     345.4 ms ±  23.0 ms    [User: 385.2 ms, System: 65.3 ms]
  Range (min … max):   328.7 ms … 405.7 ms    10 runs
Screenshot 2024-10-09 at 17 50 37
  • after (35~40ms):
hyperfine --warmup 3 'node ./node_modules/@rsbuild/core/bin/rsbuild.js build'
Benchmark 1: node ./node_modules/@rsbuild/core/bin/rsbuild.js build
  Time (mean ± σ):     308.8 ms ±   4.0 ms    [User: 350.4 ms, System: 58.6 ms]
  Range (min … max):   304.6 ms … 319.0 ms    10 runs
Screenshot 2024-10-09 at 18 09 26

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions github-actions bot added the release: performance release: performance related release(mr only) label Oct 9, 2024
@netlify
Copy link
Copy Markdown

netlify bot commented Oct 9, 2024

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 104980a
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/670a1cae5fa17e00089c1da6

@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Oct 9, 2024
@chenjiahan
Copy link
Copy Markdown
Member Author

!eco-ci

@rspack-bot
Copy link
Copy Markdown

rspack-bot commented Oct 9, 2024

📝 Ran ecosystem CI: Open

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

@chenjiahan chenjiahan changed the title perf: bundle @rspack/core perf: bundle @rspack/core for faster startup Oct 12, 2024
@chenjiahan chenjiahan removed the request for review from jerrykingxyz October 12, 2024 06:46
@chenjiahan
Copy link
Copy Markdown
Member Author

!eco-ci

@rspack-bot
Copy link
Copy Markdown

rspack-bot commented Oct 12, 2024

📝 Ran ecosystem CI: Open

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

@chenjiahan
Copy link
Copy Markdown
Member Author

The devserver CI failed because we need to update the module path snapshots. I will update them after releasing a new Rspack version.

image

@chenjiahan chenjiahan requested a review from hardfist October 12, 2024 07:17
@fi3ework
Copy link
Copy Markdown
Member

Remove some packages from prebundle.config.js because they can be bundled to dist/index.js.

Do we have guidelines for deciding when to use prebundle or direct bundle? I assume we should use prebundle when direct bundling isn't possible, as it can handle more edge cases.

@chenjiahan
Copy link
Copy Markdown
Member Author

Currently we have two cases to use prebundle:

  1. Use prebundle for chunk splitting. For example, we want to load browserslist on demand, so we can use prebundle to output a separate browserslist/index.js chunk. This can be removed after Rslib supports chunk splitting.
  2. Use prebundle to bundle the types of thrid-party packages. For example, we need the types of zod and prebundle can handle it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: performance release: performance related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants