Skip to content

perf: replace compiled imports with require - #6308

Merged
chenjiahan merged 6 commits into
mainfrom
require_compiled_package_1004
Oct 5, 2025
Merged

perf: replace compiled imports with require#6308
chenjiahan merged 6 commits into
mainfrom
require_compiled_package_1004

Conversation

@chenjiahan

Copy link
Copy Markdown
Member

Summary

Since the compiled packages are in CommonJS format, using require to import them avoids the performance overhead of cjs-module-lexer and improves startup performance.

  • consolidate all compiled package imports into a single helper function
  • remove async/await from package imports where possible
  • add vendors.ts to manage compiled package types and exports

Profile

Before

Screenshot 2025-10-04 at 22 48 25

After

Screenshot 2025-10-04 at 23 00 31

Benchmark

Before

Name Dev cold start HMR Prod build
Rsbuild 1.5.13 314ms 79ms 412ms

After

Name Dev cold start HMR Prod build
Rsbuild 1.5.13 298ms 78ms 414ms

Related Links

nodejs/node#59913

Checklist

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

Copilot AI review requested due to automatic review settings October 4, 2025 15:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 requireCompiledPackage helper function
  • Remove async/await from package imports where possible to make functions synchronous
  • Add vendors.ts to 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.

Comment thread packages/core/src/helpers/vendors.ts
Comment thread packages/core/src/helpers/vendors.ts
Comment thread packages/core/src/helpers/vendors.ts
Comment thread packages/core/src/helpers/vendors.ts
@netlify

netlify Bot commented Oct 4, 2025

Copy link
Copy Markdown

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit d1984ec
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/68e1c77025164f0008e405cb
😎 Deploy Preview https://deploy-preview-6308--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 69
Accessibility: 97
Best Practices: 100
SEO: 100
PWA: 60
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@chenjiahan
chenjiahan merged commit 3c005ca into main Oct 5, 2025
11 checks passed
@chenjiahan
chenjiahan deleted the require_compiled_package_1004 branch October 5, 2025 01:37
@chenjiahan chenjiahan mentioned this pull request Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants