Skip to content

perf(integration): skip no-op debug-ids Babel pass on files with no debuggable calls - #1762

Open
rhengles wants to merge 1 commit into
vanilla-extract-css:masterfrom
arijs:perf/skip-noop-debug-id-babel
Open

rhengles wants to merge 1 commit into
vanilla-extract-css:masterfrom
arijs:perf/skip-noop-debug-id-babel

Conversation

@rhengles

@rhengles rhengles commented Jul 2, 2026

Copy link
Copy Markdown

In debug mode (the default outside production), @vanilla-extract/integration's transform/transformSync ran every *.css.ts module through Babel so that @vanilla-extract/babel-plugin-debug-ids could attach debug IDs to calls like style(), createVar(), and createTheme().

But the plugin only ever mutates the functions in its debuggableFunctionConfig. A module that uses only non-debuggable APIs — globalStyle, globalKeyframes, globalFontFace, createThemeContract, fallbackVar, … — was parsed and fully regenerated to produce byte-identical output. For large generated stylesheets this no-op pass is expensive and also trips Babel's code-generator deopt:

[BABEL] Note: The code generator has deoptimised the styling of …/styles.css.ts as it exceeds the max of 500KB.

This shows up when vanilla-extract is generated programmatically from another source
rather than hand-authored — e.g. converting an existing CSS framework to vanilla-extract —
where the emitted per-theme stylesheets can be large and built almost entirely from
globalStyle.

Real-world case

The repo where I ran into this:
https://github.com/arijs/bootswatch-solid/tree/ve-literal-converter
(arijs/bootswatch-solid@8cc4201)

Run

npm install
npm run ve2:build

Without this optimization, the build is slower than it could optimally be.

Change

  • @vanilla-extract/babel-plugin-debug-ids exports a new helper
    mightHaveDebuggableCalls(source: string): boolean — a cheap, word-bounded regex built
    from the keys of debuggableFunctionConfig (the single source of truth for which calls get
    debug IDs).
  • @vanilla-extract/integration's transform/transformSync gate the Babel call on it:
    if (identOption === 'debug' && mightHaveDebuggableCalls(source)).

Why it's safe (no false negatives)

For the plugin to add a debug ID, the call must reference a debuggable name literally in
the source: either as a named import (import { style } or import { style as s }) or a
namespace member access (ns.style(...)). In every case the debuggable name appears verbatim
in the source text, so the pre-check sees it. The regex is word-bounded specifically so it
does not match the intentionally-excluded global* siblings (globalStyle contains
Style, not a \bstyle\b; styleVariants matches its own alternative, not style).
False positives (running Babel when nothing changes) are harmless — they just fall back to
today's behavior.

Verification

Applied to the built packages and run against a real 27-theme project (~925 *.css.ts,
several literal stylesheets >500KB, overwhelmingly globalStyle):

  • Output unchanged. A chunk-independent canonical signature of all emitted CSS — every
    rule normalized and sorted, plus the full set of VE debug class/var identifiers — is
    byte-identical with and without the change:
    • filtered single-theme build: ruleSetSig and identSetSig identical across runs.
    • full 27-theme build: 70,531 rules / 2,619 debug identifiers, identical signatures
      (ruleSetSig=f2f7b46a…, identSetSig=6592fb7f…) before and after.
  • [BABEL] … deoptimised … notes: 15 → 0 on the full build.
  • Build time: full build 1m15s → 1m8s here; the single-theme dev/capture loop dropped
    ~2× on the files that previously hit the >500KB deopt (each such file went from a
    multi-second cold Babel compile to being skipped). The win scales with how much of a
    codebase is generated globalStyle.

A focused unit test for the helper is included
(packages/babel-plugin-debug-ids/src/mightHaveDebuggableCalls.test.ts).

Test suite status

  • New helper test — mightHaveDebuggableCalls.test.ts (12 cases, all pass). Covers the
    six ways a debuggable name can appear (named import, aliased import, namespace member call,
    the styleVariants/createVar/layer alternatives) and the six that must not match
    (globalStyle, globalKeyframes, globalFontFace, createThemeContract, fallbackVar,
    and a file with no vanilla-extract at all). The createThemeContract case pins the
    word-boundary guarantee — \bcreateTheme\b deliberately does not match across the
    Contract suffix.

    • The file follows this repo's convention of importing the test globals explicitly
      (import { describe, expect, it } from 'vitest'); vitest is configured without
      globals: true, so a bare-globals test would ReferenceError at runtime.
  • Full unit run (pnpm test:unit): 436 passed, 1 skipped. The change introduces no
    regressions across the suite.

  • Pre-existing, unrelated flakes — not introduced by this PR. Two cases in
    packages/turbopack-plugin/src/index.test.ts (a self-described race-condition stress
    test
    , added in turbopack support #1639 / migrated in Migrate all tests to vitest, increase vite-node dep range #1694 — untouched by this branch) fail only inside the
    full 26-file run and pass in isolation (pnpm vitest run packages/turbopack-plugin
    → 2/2). One is a tight timeout (10 × 250ms) that the compiler-warmup iteration blows
    under full-suite CPU contention; the other is the shared-compiler staleness race the test
    exists to catch. Both are orthogonal to the debug-ids Babel path and out of scope here —
    recommend running the turbopack stress test in isolation in CI rather than masking it.

Notes

  • Only affects identOption === 'debug'. short (production) already skips Babel.
  • The esbuild integration path (vanillaExtractTransformPlugin) goes through the same
    transform, so it benefits automatically.

Local-setup-only changes — NOT included in the PR

To get pnpm install to complete on my machine (pnpm 11.8), some edits to
pnpm-workspace.yaml were required. These are unrelated to the change itself and are
left out of the PR:

  • trustPolicyExclude additions. The repo sets trustPolicy: no-downgrade, which pnpm
    enforces against every transitive dependency. Several old packages that predate npm
    provenance tripped ERR_PNPM_TRUST_DOWNGRADE (a package whose earlier version had a trusted
    publisher but the pinned version has no trust evidence). To install, each flagged name was
    added to trustPolicyExclude: rollup, algoliasearch and the @algolia/* family
    (@algolia/recommend, @algolia/client-common, @algolia/client-search,
    @algolia/logger-console, @algolia/client-analytics, @algolia/requester-node-http,
    @algolia/requester-browser-xhr, @algolia/client-personalization), and
    css-declaration-sorter. These are all pinned by upstream and mostly pulled in by the
    docs site/.
  • allowBuilds: '@parcel/watcher': false. After deps resolved, pnpm's
    ERR_PNPM_IGNORED_BUILDS demanded an explicit build-script decision for @parcel/watcher.
    Set to false to match every other native dep in that map (esbuild, sharp, lmdb, … all
    false); the prebuilt binary is used, no local compile.
  • pnpm-lock.yaml churn / pnpm-lock-git.yaml. Any local lockfile drift is likewise a
    setup artifact and should not be part of the PR.

None of the above touches the debug-ids Babel path; they only reflect this environment's
supply-chain policy gates.

…ebuggable calls

In `debug` mode (the default outside production), @vanilla-extract/integration's
`transform`/`transformSync` ran every `*.css.ts` module through Babel so that
@vanilla-extract/babel-plugin-debug-ids could attach debug IDs to calls like
`style()`, `createVar()`, and `createTheme()`. But the plugin only ever mutates the
functions in its `debuggableFunctionConfig`. A module that uses only non-debuggable
APIs — `globalStyle`, `globalKeyframes`, `globalFontFace`, `createThemeContract`,
`fallbackVar`, … — was parsed and fully regenerated to produce byte-identical output.
For large generated stylesheets this no-op pass is expensive and also trips Babel's
code-generator deopt ("… has deoptimised the styling of … as it exceeds the max of
500KB").

Introduce `mightHaveDebuggableCalls(source)` in babel-plugin-debug-ids: a cheap,
word-bounded regex compiled once from the keys of `debuggableFunctionConfig` — the
single source of truth for which calls receive debug IDs. integration's
`transform`/`transformSync` now gate the Babel call on it:
`identOption === 'debug' && mightHaveDebuggableCalls(source)`.

Safe against false negatives: a call the plugin acts on must reference a debuggable
name literally — a named import (`import { style }` / `import { style as s }`) or a
namespace member access (`ns.style(...)`) — so the name always appears verbatim in the
source text. The word boundaries keep it from matching the intentionally-excluded
`global*` siblings (`globalStyle` contains `Style`, not a `\bstyle\b`). False positives
(running Babel when nothing changes) simply fall back to today's behavior.

Emitted CSS and debug class/var identifiers are unchanged. Adds a focused unit test
for the helper.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9b1a958

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@vanilla-extract/babel-plugin-debug-ids Minor
@vanilla-extract/integration Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
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