Skip to content

perf: use dynamic imports for node:net#5314

Merged
chenjiahan merged 1 commit intomainfrom
node_net_0526
May 27, 2025
Merged

perf: use dynamic imports for node:net#5314
chenjiahan merged 1 commit intomainfrom
node_net_0526

Conversation

@chenjiahan
Copy link
Copy Markdown
Member

Summary

Replacing synchronous node:net imports with dynamic imports for better performance, and updating all calls to handle these changes.

Checklist

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

Copilot AI review requested due to automatic review settings May 26, 2025 13:29
@netlify
Copy link
Copy Markdown

netlify Bot commented May 26, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 7a9cc29
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/68346cba2b2c9c00082e0461
😎 Deploy Preview https://deploy-preview-5314--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: 77 (🟢 up 1 from production)
Accessibility: 97 (no change from production)
Best Practices: 92 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Improves startup performance by replacing static node:net imports with dynamic imports and converting related utility functions to async.

  • Introduce dynamic imports for createServer and isIPv6 in helper utilities
  • Update getHostInUrl and getAddressUrls to return promises
  • Await new async functions in prodServer.ts, devServer.ts, and open.ts

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
packages/core/src/server/prodServer.ts Added await for getAddressUrls
packages/core/src/server/open.ts Changed getHostInUrl call to await the async function
packages/core/src/server/helper.ts Switched from static node:net import to dynamic imports and updated function signatures to async
packages/core/src/server/devServer.ts Added await for getAddressUrls
Comments suppressed due to low confidence (1)

packages/core/src/server/helper.ts:412

  • New async behavior in getAddressUrls should be covered by unit tests—verify both host-specific and multi-interface address branches.
export const getAddressUrls = async ({

tryLimits = 1;
}

const { createServer } = await import('node:net');
Copy link

Copilot AI May 26, 2025

Choose a reason for hiding this comment

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

Consider hoisting the dynamic import of createServer outside of the loop or caching the imported module to avoid repeated import overhead on subsequent calls.

Suggested change
const { createServer } = await import('node:net');
if (!cachedCreateServer) {
const { createServer } = await import('node:net');
cachedCreateServer = createServer;
}
const createServer = cachedCreateServer;

Copilot uses AI. Check for mistakes.
Comment thread packages/core/src/server/helper.ts
Comment thread packages/core/src/server/helper.ts
@chenjiahan chenjiahan merged commit c633c0f into main May 27, 2025
12 checks passed
@chenjiahan chenjiahan deleted the node_net_0526 branch May 27, 2025 01:10
@chenjiahan chenjiahan mentioned this pull request May 27, 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