Skip to content

perf: memoize unitless CSS property classification - #956

Merged
trueadm merged 3 commits into
mainfrom
cursor/runtime-perf-audit-d1f9
Sep 5, 2026
Merged

trueadm merged 3 commits into
mainfrom
cursor/runtime-perf-audit-d1f9

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Memoizes isUnitlessStyleProp in dom-tables.js with the same Map-cache pattern styleName already uses. cssStyleValue called this helper on every numeric style write (client animation, SSR styleObjectToCss, compiler bake) and previously paid replaceAll('-', '') + toLowerCase on 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_PROPS scan. false is 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:

  • escapeHtml indexOf reject 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.
  • escapeHtml dirty char-walk (~2.5× helper): same page-level reason.
  • escapeAttr indexOf (~1.0×).
  • VALID_ATTR_NAME char-walk (~1.1–1.7×, noisy).

isUnitlessStyleProp Map cache was ~12× on the helper and ~6.8× on cssStyleValue in a throwaway microbench (Node v22.22.2, 3 runs, mixed camel/kebab/vendor, 200 warmup then 1e6 timed). Production cssStyleValue vs inlined prior scan is ~3.1–3.4× in benchmarks/style-unitless. Unique never-repeated keys are not claimed as a win.

Production bench (Node v22.22.2, Linux 6.12.94+, 4 CPUs)

node benchmarks/style-unitless/run.mjs 8

Scores are ms / 1,000 lookups (lower is better).

run scan-mixed cached-mixed ratio
A 0.994 0.295 0.297× (~3.4×)
B 0.973 0.319 0.328× (~3.1×)
after checksum fix 0.990 0.293 0.296× (~3.4×)
node benchmarks/bench.mjs --quick --ratios style-unitless
run scan-mixed cached-mixed ratio
quick (pre-fix) 0.983 0.302 0.307×, guard PASS (maxRatio 0.5)
quick (after checksum fix) 1.024 0.319 guard PASS

cached-mixed is production cssStyleValue. scan-mixed inlines the pre-cache isUnitlessStyleProp scan 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 times LOOKUPS_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-mixed maxRatio 0.5.
  • .changeset/style-unitless-cache.md — octane patch.

Validation

  • pnpm format:files:check on changed JS/TS/JSON
  • tsgo --noEmit -p packages/octane/tsconfig.json
  • targeted tests: packages/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 8 and node benchmarks/bench.mjs --quick --ratios style-unitless after the checksum fix — both complete green
  • GitHub Actions on 502865fb2: lint, typecheck, test (24), React parity, examples, heavy integration, website, Three/Lynx, publishable packages, CI provenance — all successful

Risk / follow-ups

  • Cache is unbounded in theory but keyed only by CSS property names actually written; same bound as the existing styleName cache.
  • Unique never-repeated keys pay Map.set plus the original scan; not claimed as a win.
  • escapeHtml remains a smaller SSR helper candidate if a later pass can show a real page-level win.

Provenance

  • An agent produced this diff (agent-authored)

This PR memoizes isUnitlessStyleProp in dom-tables.js with a Map cache, matching styleName. cssStyleValue used to replaceAll + toLowerCase on every numeric style write. Production bench (cssStyleValue vs inlined prior scan): ~3.1–3.4× on mixed camel/kebab/vendor bags. Orthogonal to #951/#955.

Open in Web Open in Cursor 

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

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]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Sep 4, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

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.

Create PR

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.

Comment thread benchmarks/style-unitless/run.mjs Resolved
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
jonkwheeler marked this pull request as ready for review September 4, 2026 18:14
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent and removed agent-authored Diff or issue body substantially produced by an AI agent labels Sep 4, 2026
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]>
@cursor

cursor Bot commented Sep 4, 2026

Copy link
Copy Markdown

READY FOR REVIEW

@trueadm
trueadm merged commit 3988e85 into main Sep 5, 2026
31 checks passed
@trueadm
trueadm deleted the cursor/runtime-perf-audit-d1f9 branch September 5, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work READY FOR REVIEW

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants