perf(hmr): reduce stats.toJson() calls - #6301
Conversation
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
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
getStatsOptionswith 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
getStatsOptionsfunction is called without theactionparameter 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.
stats.toJson() calls
There was a problem hiding this comment.
💡 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

Summary
getStatsOptions, adding minimal default options to keep the JSON output consistent.Before
After
Checklist