Repository navigation
perf: memoize unitless CSS property classification - #956
Merged
Merged
Conversation
Cache isUnitlessStyleProp results like styleName so repeated numeric style writes skip replaceAll + toLowerCase allocation. Same px/unitless contract for camelCase, kebab-case, and vendor-prefixed keys. Co-authored-by: Jon Wheeler <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Bench checksum rejects timed samples
- Scaled the warmup CSS-length checksum from 200 lookups to LOOKUPS_PER_SAMPLE so timed samples no longer fail the equality gate.
Or push these changes by commenting:
@cursor push 7a28e9b686
Preview (7a28e9b686)
diff --git a/benchmarks/style-unitless/run.mjs b/benchmarks/style-unitless/run.mjs
--- a/benchmarks/style-unitless/run.mjs
+++ b/benchmarks/style-unitless/run.mjs
@@ -5,6 +5,7 @@
const iterations = Number.parseInt(process.argv[2] ?? '8', 10);
const LOOKUPS_PER_SAMPLE = 1_000_000;
+const WARMUP_LOOKUPS = 200;
if (!Number.isSafeInteger(iterations) || iterations < 1) {
throw new Error('style-unitless iterations must be a positive integer');
@@ -144,10 +145,10 @@
const expectedChecksums = new Map();
for (const scenario of scenarios) {
- const warmup = runLookups(scenario.serialize, scenario.names, scenario.nums, 200);
- const control = runLookups(cssStyleValueScan, scenario.names, scenario.nums, 200);
+ const warmup = runLookups(scenario.serialize, scenario.names, scenario.nums, WARMUP_LOOKUPS);
+ const control = runLookups(cssStyleValueScan, scenario.names, scenario.nums, WARMUP_LOOKUPS);
assert.equal(warmup.checksum, control.checksum, scenario.name + ' warmup drifted');
- expectedChecksums.set(scenario.name, warmup.checksum);
+ expectedChecksums.set(scenario.name, warmup.checksum * (LOOKUPS_PER_SAMPLE / WARMUP_LOOKUPS));
}
const samples = new Map();You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 0ac824c. Configure here.
Warmup and timed loops do different iteration counts; compare per-bag checksums instead of raw sums. Relax the ratio ceiling to the measured 0.31x production win. Co-authored-by: Jon Wheeler <[email protected]>
jonkwheeler
marked this pull request as ready for review
September 4, 2026 18:14
Bugbot was right: the warmup bag checksum cannot be compared to a LOOKUPS_PER_SAMPLE timed run. Keep a small JIT warmup, then derive the assert baseline from one bag times the timed count. Co-authored-by: Jon Wheeler <[email protected]>
|
READY FOR REVIEW |
14 of 21 tasks
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.


Summary
Memoizes
isUnitlessStylePropindom-tables.jswith the same Map-cache patternstyleNamealready uses.cssStyleValuecalled this helper on every numeric style write (client animation, SSRstyleObjectToCss, compiler bake) and previously paidreplaceAll('-', '')+toLowerCaseon every lookup, including negative hits (width,fontSize).The cache is bounded by the CSS-property key universe. Cache misses still run the original
UNITLESS_STYLE_PROPSscan.falseis a valid cached miss, so the lookup uses!== undefined.No public API change.
Orthogonal to #951 (static router Map) and #955 (last-static-segment index). Those PRs stay untouched.
Why this candidate
Third-pass audit measured before changing. Discarded:
escapeHtmlindexOfreject on clean strings (~1.7–2.4× helper): page-clean 500-title SSR dropped ~25µs → ~10µs, not a meaningful end-to-end win.escapeHtmldirty char-walk (~2.5× helper): same page-level reason.escapeAttrindexOf(~1.0×).VALID_ATTR_NAMEchar-walk (~1.1–1.7×, noisy).isUnitlessStylePropMap cache was ~12× on the helper and ~6.8× oncssStyleValuein a throwaway microbench (Node v22.22.2, 3 runs, mixed camel/kebab/vendor, 200 warmup then 1e6 timed). ProductioncssStyleValuevs inlined prior scan is ~3.1–3.4× inbenchmarks/style-unitless. Unique never-repeated keys are not claimed as a win.Production bench (Node v22.22.2, Linux 6.12.94+, 4 CPUs)
Scores are ms / 1,000 lookups (lower is better).
maxRatio0.5)cached-mixedis productioncssStyleValue.scan-mixedinlines the pre-cacheisUnitlessStylePropscan so the comparison is this change, not a different CSS writer.Semantic gates: both writers emit the same CSS strings; unitless classification matches
UNITLESS_STYLE_PROPS. Timed-sample checksum is now one bag timesLOOKUPS_PER_SAMPLE(warmup stays 200 for JIT only).Files
packages/octane/src/dom-tables.js—unitlessStylePropCache.packages/octane/tests/style-px.test.ts— kebab, repeated-key, SSR kebab + vendor cases.benchmarks/style-unitless/— Node-only suite.benchmarks/baselines/ratios.json—cached-mixed / scan-mixedmaxRatio0.5..changeset/style-unitless-cache.md—octanepatch.Validation
pnpm format:files:checkon changed JS/TS/JSONtsgo --noEmit -p packages/octane/tsconfig.jsonpackages/octane/tests/style-px.test.ts(30 passed, octane + octane-prod)packages/octane-mcp-server/src/index.test.js(15 passed)packages/octane/tests/conformance/{css-properties,ssr-serialization,dom-component-styles}.test.ts(250 passed)node benchmarks/style-unitless/run.mjs 8andnode benchmarks/bench.mjs --quick --ratios style-unitlessafter the checksum fix — both complete green502865fb2: lint, typecheck, test (24), React parity, examples, heavy integration, website, Three/Lynx, publishable packages, CI provenance — all successfulRisk / follow-ups
styleNamecache.escapeHtmlremains a smaller SSR helper candidate if a later pass can show a real page-level win.Provenance
agent-authored)This PR memoizes
isUnitlessStylePropindom-tables.jswith a Map cache, matchingstyleName.cssStyleValueused toreplaceAll+toLowerCaseon every numeric style write. Production bench (cssStyleValuevs inlined prior scan): ~3.1–3.4× on mixed camel/kebab/vendor bags. Orthogonal to #951/#955.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.