Skip to content

perf(css): reuse Sass async compiler - #1001

Merged
sxzz merged 1 commit into
mainfrom
codex/issue-1000
Jul 6, 2026
Merged

sxzz merged 1 commit into
mainfrom
codex/issue-1000

Conversation

@sxzz

@sxzz sxzz commented Jul 6, 2026

Copy link
Copy Markdown
Member
  • This PR contains AI-generated code, but I have carefully reviewed it myself. Otherwise, my PR may be closed.

Description

Fixes #1000.

@tsdown/css now reuses a Sass AsyncCompiler when the loaded Sass implementation exposes initAsyncCompiler(). This avoids module-level compileStringAsync() spawning an embedded compiler for each SCSS transform. The compiler is disposed after non-watch builds and when the watcher closes, so watch rebuilds can keep reusing it between runs.

This also adds focused tests for async compiler reuse and fallback to module-level Sass compilation.

Linked Issues

Fixes #1000

Additional context

Validated with:

  • pnpm format
  • pnpm lint
  • pnpm typecheck
  • pnpm test run

@netlify

netlify Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for tsdown-main ready!

Name Link
🔨 Latest commit 465372d
🔍 Latest deploy log https://app.netlify.com/projects/tsdown-main/deploys/6a4bf6ee6dbf1900085010c1
😎 Deploy Preview https://deploy-preview-1001--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.

@pkg-pr-new

pkg-pr-new Bot commented Jul 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

tsdown

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

create-tsdown

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

@tsdown/css

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

@tsdown/exe

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

tsdown-migrate

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

commit: 465372d

@sxzz
sxzz marked this pull request as ready for review July 6, 2026 18:43
Copilot AI review requested due to automatic review settings July 6, 2026 18:43
@sxzz
sxzz merged commit 0aa2baf into main Jul 6, 2026
18 checks passed
@sxzz
sxzz deleted the codex/issue-1000 branch July 6, 2026 18:44

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 improves SCSS/Sass preprocessing performance in @tsdown/css by reusing a persistent Sass AsyncCompiler (when supported by the loaded Sass implementation) instead of relying on the module-level compileStringAsync() that may spawn and dispose an embedded compiler per transform (notably in sass-embedded). It also ensures the compiler is disposed appropriately and adds targeted tests for the new behavior.

Changes:

  • Add a small internal abstraction (SassModule / SassCompiler) and implement loadSassCompiler() to reuse a singleton async compiler when initAsyncCompiler() is available.
  • Ensure the async compiler is disposed after non-watch builds and when the watcher closes.
  • Add tests covering async compiler reuse/disposal and fallback to module-level compilation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/css/src/preprocessors.ts Introduces async compiler reuse with loadSassCompiler() and cleanup via disposeSassCompiler(), and routes Sass compilation through the reusable compiler.
packages/css/src/preprocessors.test.ts Adds focused Vitest coverage for compiler reuse, single-init behavior, disposal, and fallback.
packages/css/src/plugin.ts Disposes the shared Sass compiler at appropriate lifecycle hooks (non-watch closeBundle, watch closeWatcher).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

@tsdown/css should reuse sass-embedded AsyncCompiler instead of spawning a compiler per SCSS transform

2 participants