Skip to content

Speed up transform() on large stylesheets - #214

Open
quantizor wants to merge 4 commits into
masterfrom
cursor/faster-transform-fcab
Open

quantizor wants to merge 4 commits into
masterfrom
cursor/faster-transform-fcab

Conversation

@quantizor

@quantizor quantizor commented Oct 29, 2026 •

Copy link
Copy Markdown

transform() is about 38% faster on a large stylesheet, with the same return values, thrown errors, and type declarations.

getPropertyName keeps one camelized string for each known stylesheet name (React Native style properties and this library's shorthands). Any other name is camelized and not retained. directionFactory, getStylesForProperty, and the transform parser build their result objects by assignment. The four direction keys, and the X and Y keys for two-argument transform functions, are created once when the factory is created.

Before and after are master and this branch. Node 22.23.4, 7 rounds of 8 interleaved samples, one process. Workload: card.css and feed.css, numeric lengths varied and repeated to 5040 rules and 26280 declarations. 8640 of those declarations are shorthands, timed on their own. NODE_ENV was unset, which is the same condition as the 3.2.0 comparison. Output diffs on all 5040 rules, including thrown messages and key order: 0.

pass before median before p95 after median after p95
transform, 5040 rules 39.11 ms 42.74 ms 24.07 ms 26.78 ms
shorthand decls, 8640 22.05 ms 25.10 ms 16.10 ms 18.53 ms

With NODE_ENV=production the same runs go from 33.74 ms to 18.82 ms median (p95 37.48 ms to 20.06 ms) on the full pass, and from 17.99 ms to 12.15 ms (p95 19.25 ms to 13.80 ms) on shorthand declarations. Output diffs: 0.

Compatibility: with NODE_ENV unset, lint, tsc, format, and the unit suite pass (19 files, 270 tests). With NODE_ENV=production, 266 tests pass and the same 4 fail as on master: the dev unit warnings and the Failed to parse declaration "..." wrapper are off in production, so those tests see Unexpected token type: word and no warning. The emitted index.d.ts matches master. No dependencies were added. A patch changeset is included.

Open in Web Open in Cursor 

Cache camelized property names and hoist direction-shorthand keys once
per factory. On a 5k-rule stylesheet, transform() is about 28% faster
with identical output.

Co-authored-by: Evan Jacobs <quantizor@users.noreply.github.com>
@changeset-bot

changeset-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bbd29ba

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

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

The fixture recorded the previous build and fails when NODE_ENV is production, because dev error text is different there.
Keep a fixed table of stylesheet names instead of an unbounded map, and build result objects by assignment.
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