perf(css): skip renderChunk when no CSS has been collected - #967
Merged
Conversation
`renderChunk` is called once per output chunk. In unbundle mode, a large package (e.g. 818 files) triggers 818 Rust→JS boundary crossings even when the package contains zero CSS files. Each call allocates via `Object.keys(chunk.modules)` and performs Map lookups before returning null. Adding an early exit when `styles` is empty eliminates all 818 calls for CSS-free packages. Observed via rolldown's PLUGIN_TIMINGS warning flagging `tsdown:css-post` at 55–67% of plugin time on TypeScript-only packages.
✅ Deploy Preview for tsdown-main ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds a guard in the CSS post-processing Rollup plugin to skip renderChunk work when there are no collected styles, avoiding unnecessary processing for chunks with no CSS.
Changes:
- Early-return from
renderChunkwhenstyles.size === 0. - Prevents subsequent non-essential logic from running for style-less chunks when CSS splitting is disabled.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
35
to
37
| renderChunk(_code, chunk) { | ||
| if (styles.size === 0) return | ||
| if (config.splitting) return |
tsdown
create-tsdown
@tsdown/css
@tsdown/exe
tsdown-migrate
commit: |
sxzz
approved these changes
Jun 6, 2026
sxzz
enabled auto-merge (squash)
June 6, 2026 15:58
sxzz
approved these changes
Jun 6, 2026
sxzz
pushed a commit
to spokodev/tsdown
that referenced
this pull request
Jun 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
I noticed rolldown's
PLUGIN_TIMINGSwarning flaggingtsdown:css-postat 55–67% of plugin time on packages that contain zero CSS files.Root cause:
renderChunkinCssPostPluginis called once per output chunk. In unbundle mode, a large TypeScript-only package (e.g. 818 files) triggers 818 Rust→JS boundary crossings even whenstylesis always empty. Each call:Object.keys(chunk.modules)nullimmediately since no CSS was ever collectedThe overhead scales linearly with output file count and is entirely wasted for CSS-free packages.
Fix
One-line early exit at the top of
renderChunk:When no CSS has been collected (no
.css/.scss/.lessfiles were transformed), all 818renderChunkcalls return immediately without touchingchunk.modules.Result
Before:
PLUGIN_TIMINGSfires on@amplitude/types(818 output files, zero CSS):After: warning gone entirely.