Repository navigation
Conversation
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 detectedLatest 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.
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.
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.
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 seeUnexpected token type: wordand no warning. The emitted index.d.ts matches master. No dependencies were added. A patch changeset is included.