perf: replace compiled imports with require - #6308
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes startup performance by replacing ES module imports with CommonJS require calls for compiled packages. Since the compiled packages are in CommonJS format, using require avoids the performance overhead of Node.js's cjs-module-lexer and improves cold start times by ~16ms based on the benchmarks.
Key changes:
- Consolidate all compiled package imports into a single
requireCompiledPackagehelper function - Remove async/await from package imports where possible to make functions synchronous
- Add
vendors.tsto centrally manage compiled package types and exports
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/helpers/vendors.ts | New helper module with requireCompiledPackage function and type definitions |
| packages/core/src/helpers/index.ts | Export vendors and remove direct picocolors import |
| packages/core/src/server/*.ts | Replace async imports with synchronous requireCompiledPackage calls |
| packages/core/src/plugins/*.ts | Convert async plugin setup to synchronous using new helper |
| packages/core/src/loader/transformLoader.ts | Make source map merging synchronous |
| packages/core/rslib.config.ts | Update error message to reference new helper |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Since the compiled packages are in CommonJS format, using
requireto import them avoids the performance overhead of cjs-module-lexer and improves startup performance.vendors.tsto manage compiled package types and exportsProfile
Before
After
Benchmark
Before
After
Related Links
nodejs/node#59913
Checklist