Skip to content

perf(css): skip renderChunk when no CSS has been collected - #967

Merged
sxzz merged 1 commit into
rolldown:mainfrom
ShMcK:fix/css-post-skip-when-no-styles
Jun 6, 2026
Merged

perf(css): skip renderChunk when no CSS has been collected#967
sxzz merged 1 commit into
rolldown:mainfrom
ShMcK:fix/css-post-skip-when-no-styles

Conversation

@ShMcK

@ShMcK ShMcK commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Problem

I noticed rolldown's PLUGIN_TIMINGS warning flagging tsdown:css-post at 55–67% of plugin time on packages that contain zero CSS files.

Root cause: renderChunk in CssPostPlugin is called once per output chunk. In unbundle mode, a large TypeScript-only package (e.g. 818 files) triggers 818 Rust→JS boundary crossings even when styles is always empty. Each call:

  1. Allocates via Object.keys(chunk.modules)
  2. Performs a Map lookup per module ID
  3. Returns null immediately since no CSS was ever collected

The 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:

if (styles.size === 0) return

When no CSS has been collected (no .css/.scss/.less files were transformed), all 818 renderChunk calls return immediately without touching chunk.modules.

Result

Before: PLUGIN_TIMINGS fires on @amplitude/types (818 output files, zero CSS):

[PLUGIN_TIMINGS] Your build spent significant time in plugins. Here is a breakdown:
  - tsdown:css-post (64%)
  - rolldown-plugin-dts:fake-js (21%)

After: warning gone entirely.

`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.
Copilot AI review requested due to automatic review settings June 4, 2026 18:11
@netlify

netlify Bot commented Jun 4, 2026

Copy link
Copy Markdown

Deploy Preview for tsdown-main ready!

Name Link
🔨 Latest commit 788ab97
🔍 Latest deploy log https://app.netlify.com/projects/tsdown-main/deploys/6a21bfe5ca0a050008f7ba84
😎 Deploy Preview https://deploy-preview-967--tsdown-main.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

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

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 renderChunk when styles.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 thread packages/css/src/post.ts
Comment on lines 35 to 37
renderChunk(_code, chunk) {
if (styles.size === 0) return
if (config.splitting) return
@pkg-pr-new

pkg-pr-new Bot commented Jun 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

tsdown

pnpm add https://pkg.pr.new/tsdown@967 -D
npm i https://pkg.pr.new/tsdown@967 -D
yarn add https://pkg.pr.new/tsdown@967.tgz -D

create-tsdown

pnpm add https://pkg.pr.new/create-tsdown@967 -D
npm i https://pkg.pr.new/create-tsdown@967 -D
yarn add https://pkg.pr.new/create-tsdown@967.tgz -D

@tsdown/css

pnpm add https://pkg.pr.new/@tsdown/css@967 -D
npm i https://pkg.pr.new/@tsdown/css@967 -D
yarn add https://pkg.pr.new/@tsdown/css@967.tgz -D

@tsdown/exe

pnpm add https://pkg.pr.new/@tsdown/exe@967 -D
npm i https://pkg.pr.new/@tsdown/exe@967 -D
yarn add https://pkg.pr.new/@tsdown/exe@967.tgz -D

tsdown-migrate

pnpm add https://pkg.pr.new/tsdown-migrate@967 -D
npm i https://pkg.pr.new/tsdown-migrate@967 -D
yarn add https://pkg.pr.new/tsdown-migrate@967.tgz -D

commit: 788ab97

@sxzz
sxzz enabled auto-merge (squash) June 6, 2026 15:58
@sxzz
sxzz merged commit 9f05179 into rolldown:main Jun 6, 2026
16 checks passed
sxzz pushed a commit to spokodev/tsdown that referenced this pull request Jun 18, 2026
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.

3 participants