Skip to content

perf(ssr): skip reaggregation of canonical attributes - #964

Merged
trueadm merged 2 commits into
mainfrom
fix/runtime-perf-hunt-20260905
Sep 5, 2026
Merged

trueadm merged 2 commits into
mainfrom
fix/runtime-perf-hunt-20260905

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Production SSR currently builds a second attribute map and an ordered array even when all final attribute names are already canonical. This change serializes those entries directly from the existing raw-writer map, preserving insertion order and final values. Aliases and noncanonical HTML casing retain the existing aggregation path.

The production-only check runs after every source read. Serialization still uses the existing escaping, filtering, class/style, namespace, and form-control rules. There are no compiler, client-runtime, public API, or persistent-cache changes.

Performance evidence

Profiled the existing deopt-page/octane-fast SSR fixture before choosing the optimization: attribute aggregation accounted for 18.3% CPU self time. The fixture renders 300 cards, 601 components, and 300 aggregated attribute sets.

Two independent series used fresh processes in ABBAABBA order, four samples per version, 5-second steady windows after 0.5-second warmup. Each render includes response-body materialization. The score is the median of the four raw steady-window mean render times; no control normalization was applied.

Workload First series baseline -> change Confirmation baseline -> change
Canonical attributes (primary) 2.4011 -> 2.0285 ms (15.52% faster) 2.4220 -> 2.0014 ms (17.36% faster)
Late alias (fallback control) 2.5289 -> 2.6311 ms (4.04% slower) 2.5370 -> 2.6631 ms (4.97% slower)
Escape-heavy negative control 1.56% faster 2.39% faster

Tradeoff: a late alias makes the new scan fall back to the original path, adding a repeatable 4-5% cost in that control. The confirmation median is just 0.03 percentage points below the preregistered 5% material-regression cutoff; two individual confirmation pairs exceeded 5%. This is a measured canonical-attribute improvement, not a universal SSR speedup.

The primary gain exceeded the registered 5.87% unchanged-run noise in both series. Every primary pair improved and the version ranges were disjoint. Confirmation baseline spread was 11.95% because one run was slower; even the smallest paired improvement was 13.34%. The escape-heavy control stayed within its independently measured noise. Descriptor, waterfall, replay/resource, and late-alias aggregate controls passed the preregistered gates. All 13 fixture modes produced matching complete responses; resource HTML, head, and CSS outputs also matched separately.

Measured on Apple M3 arm64, Node 22.22.2 / V8 12.4, against 28907dbd81c51d99732216d871c742fab2d3370a. Results describe these workloads on this machine. The measured fixture bundle grows 554 raw bytes / 113 gzip bytes; the resource fixture bundle is unchanged. Scratch profiling and comparison harnesses are not shipped.

Validation

  • Production-bundle public rendering tests cover getter/Proxy reads, repeated writers, coercion order and exceptions, aliases/casing, custom elements, SVG/MathML, form controls, and raw HTML filtering. Relevant mutants fail these tests.
  • 994 tests passed across the owning SSR, hydration, attribute, and streaming suites. The full root pnpm test suite was not run locally; targeted ownership suites were used for this 27-line runtime change.
  • 36 website production-build browser tests passed, including hydration and interaction checks.
  • Repository-wide typecheck and formatting passed; changeset and generated-file synchronization checks passed.
  • Integrated-browser production smoke checks passed for /, /docs/core-apis, and /docs/bindings, including state updates, form actions, and category filtering; no console errors.
  • Eight local specialist reviews found no actionable issues. An optional test gap remains for bundled URL sanitization/quote escaping; source tracing confirms the shared protections remain in use.
  • Patch changeset included.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Touches core production attribute serialization semantics; regressions would change HTML output or prop read/coercion order, though behavior is heavily covered by new bundled SSR tests.

Overview
Production SSR now takes a fast path in ssrAttrs when every collected prop name is already canonical (no alias pairs like className/class, and HTML names are lowercased as expected). In that case it serializes straight from the existing raw-writer Map instead of building the second resolved map and sort path, while still honoring spread precedence, coercion order, and the same ssrAttrEntry filtering (form controls, dangerouslySetInnerHTML, etc.).

When any name would need normalization or alias merging, behavior stays on the existing aggregation path (dev builds always use that path).

Adds production-bundled SSR tests for spread/getter read order, coercion and errors, alias winners, SVG/MathML/custom elements, form control projection, and raw HTML—plus an octane patch changeset.

Reviewed by Cursor Bugbot for commit b04e32e. Bugbot is set up for automated code reviews on this repo. Configure here.


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

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Sep 5, 2026
@jonkwheeler
jonkwheeler marked this pull request as ready for review September 5, 2026 04:45
@jonkwheeler

Copy link
Copy Markdown
Contributor Author

Performance workflow validation is complete at b04e32e3dca07d655c69bf19bfe76c581c2a095d:

  • All current-head checks are terminal with no failures (31 successful check results, including the full CI run and Cursor Bugbot; remaining results are skipped conditional/draft checks).
  • No unresolved review threads or actionable feedback were found. No CI fixes or feedback-driven commits were needed during the approximately seven-minute CI follow-up.
  • The PR is open and ready for review, and its head contains the live main tip 28907dbd81c51d99732216d871c742fab2d3370a. GitHub reports no merge conflict.
  • GitHub still reports REVIEW_REQUIRED and merge state BLOCKED. A qualifying reviewer approval is the remaining human gate; this is not a merge-ready or merged claim. Automated follow-up is stopping here.

The PR description records the two primary workload gains (15.52% and 17.36%) and the repeatable late-alias fallback cost (4.04% and 4.97%).

@trueadm
trueadm merged commit a40dae1 into main Sep 5, 2026
49 checks passed
@trueadm
trueadm deleted the fix/runtime-perf-hunt-20260905 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants