Skip to content

perf(core): reduce file size report allocations#7941

Open
chenjiahan wants to merge 1 commit into
mainfrom
chenjiahan/perf-file-size-allocations
Open

perf(core): reduce file size report allocations#7941
chenjiahan wants to merge 1 commit into
mainfrom
chenjiahan/perf-file-size-allocations

Conversation

@chenjiahan

@chenjiahan chenjiahan commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary

This PR reduces allocation overhead in the file size reporter while keeping the same reporting behavior.

It avoids building unused snapshot data when diff output is disabled, folds asset collection/filtering/formatting into one traversal, skips default-excluded assets before materializing content, and reduces temporary path/width calculation arrays.

Performance data:

  • @rsbuild/core self time: 49.8 ms -> 42.1 ms (-7.7 ms)
  • file-size plugin range self time: 20.6 ms -> 12.5 ms (-8.2 ms)

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6d1a5454-365d-406b-97a9-b4eaa2e7717b

📥 Commits

Reviewing files that changed from the base of the PR and between efe4fbd and 76cb44a.

📒 Files selected for processing (1)
  • packages/core/src/plugins/fileSize.ts

📝 Walkthrough

Walkthrough

packages/core/src/plugins/fileSize.ts receives several coordinated internal changes. FormattedAsset drops the filename field in favor of precomputed filenameLabel/filenameLength. StatsAsset.content becomes optional. gzipSize uses the result buffer's .length instead of Buffer.byteLength. A new getFilePath helper strips query strings from asset keys. getAssets becomes a single-pass loop using getFilePath, inline exclude/include filtering, and conditional content computation. Filename labeling switches from path.dirname/path.basename to a lastIndexOf('/') split. printFileSizes gains a saveSnapshot parameter, gating snapshot object creation independently from diff-label computation. Table column widths are computed via an explicit loop that also tracks hasGzipSize. The call site passes showDiff as saveSnapshot.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main optimization focus: reducing allocations in the file size reporting functionality.
Description check ✅ Passed The description clearly relates to the changeset by explaining the allocation reduction strategies and providing performance metrics that validate the optimization.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant