Skip to content

perf(hmr): reduce stats.toJson() calls - #6301

Merged
chenjiahan merged 4 commits into
mainfrom
merge_stats_json_1003
Oct 3, 2025
Merged

perf(hmr): reduce stats.toJson() calls#6301
chenjiahan merged 4 commits into
mainfrom
merge_stats_json_1003

Conversation

@chenjiahan

@chenjiahan chenjiahan commented Oct 3, 2025

Copy link
Copy Markdown
Member

Summary

Before

Screenshot 2025-10-03 at 15 48 24

After

Screenshot 2025-10-03 at 15 46 55

Checklist

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

Copilot AI review requested due to automatic review settings October 3, 2025 07:44
@netlify

netlify Bot commented Oct 3, 2025

Copy link
Copy Markdown

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 7d4dcd0
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/68df8299583b330008dde6ba
😎 Deploy Preview https://deploy-preview-6301--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: 73 (🟢 up 3 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (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.

@chenjiahan chenjiahan changed the title perf: merge stats.toJson perf(hmr): reduce stats.toJson() calls Oct 3, 2025

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 build statistics performance by caching stats on the shared build state and centralizing stats option handling. The key performance improvement is storing the latest build stats on the build state to reuse them instead of repeatedly calling toJson() on raw stats objects.

Key changes:

  • Added cached stats storage to the build state and reset them on invalidation
  • Centralized stats option merging in getStatsOptions with minimal defaults for consistent JSON output
  • Refactored the dev socket server to consume cached stats instead of storing raw stats objects

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/core/src/types/rsbuild.ts Extended RsbuildStatsItem to include entrypoints and hash fields
packages/core/src/types/context.ts Added ActionType and stats field to BuildState
packages/core/src/server/socketServer.ts Major refactor to use cached stats and simplified stats handling
packages/core/src/server/assets-middleware/index.ts Removed stats parameter from onBuildDone callback
packages/core/src/provider/createCompiler.ts Added stats caching and uses centralized getStatsOptions
packages/core/src/helpers/stats.ts Enhanced getStatsOptions with action-specific defaults
packages/core/src/createContext.ts Initialize stats field in buildState
packages/compat/webpack/src/createCompiler.ts Updated to use cached stats approach
e2e/cases/server/overlay-type-errors/index.test.ts Temporarily disabled failing test
Comments suppressed due to low confidence (1)

packages/core/src/helpers/stats.ts:1

  • The getStatsOptions function is called without the action parameter in the webpack compatibility layer, missing the performance optimization for dev mode where hash and entrypoints are conditionally included.
import color from '../../compiled/picocolors/index.js';

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread packages/core/src/server/socketServer.ts
@chenjiahan chenjiahan changed the title perf(hmr): reduce stats.toJson() calls perf(hmr): reduce stats.toJson() calls Oct 3, 2025

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment thread packages/compat/webpack/src/createCompiler.ts
@chenjiahan
chenjiahan merged commit fcc69bf into main Oct 3, 2025
11 checks passed
@chenjiahan
chenjiahan deleted the merge_stats_json_1003 branch October 3, 2025 11:42
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