Skip to content

perf: reduce SSR HTML payload and hydration markers - #710

Merged
trueadm merged 2 commits into
octanejs:mainfrom
openai-oss-forks:fix/ssr-html-payload
Aug 11, 2026
Merged

trueadm merged 2 commits into
octanejs:mainfrom
openai-oss-forks:fix/ssr-html-payload

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Reduce Octane's hydratable HTML without changing visible markup, removing necessary hydration ownership, or adding SSR overhead. The compiler and runtime now reuse boundaries that are already proven to own a keyed item or control-flow arm, and streamed Suspense segments escape only script-shaped HTML tokens.

Why

Octane's ordinary 50-card news fixture is only 34 raw HTML bytes larger than React, but it hides the real problem: component-heavy and binding-style pages stack redundant hydration ranges, while streamed segments previously expanded every < into \u003c. Production comparisons against the same visible markup show substantially larger and independently fixable costs.

Production scenario Before, raw bytes After, raw bytes Raw bytes saved Comments removed gzip bytes saved Brotli bytes saved
Compiled keyed component lists, 300 cards 138,989 134,189 4,800 600 92 85
Binding-style host descriptors, 300 cards 157,619 148,003 9,616 1,202 173 97
Fully specified host-only @if / @switch, 300 rows 55,570 45,970 9,600 1,200 82 56
Ten-boundary streamed Suspense response 22,823 20,163 2,660 — ≈75 ≈40

These are separate fixtures, not additive savings on one response. Stream compression varies slightly with per-response boundary identifiers.

Changes

  • Reuse a same-module, single-host-root component's existing hydration range for eligible keyed @for items. Imported components, explicit component keys, spreads, ambiguous roots, and other unproven shapes retain their existing boundaries.
  • Let descriptor-authored keyed host items delimit themselves only when the actual child value already captured for serialization is primitive or empty. Preserve descriptor field evaluation order, accessors, forwarding Proxies, asynchronous identity scopes, mixed lists, and legacy marked hydration. The proof adds no WeakSet registration, reflection, per-host allocation, or SSR throughput penalty.
  • Borrow the existing control-flow slot range for fully specified @if / @else and @switch / @default arms when every arm is proven to be one ordinary host. Incomplete branches, setup statements, fragments, components, hoisted head resources, and streaming boundaries remain conservatively marked.
  • Keep streamed JSON carriers safe by escaping both opening and closing script tokens case-insensitively, including HTML-tokenizer double-escape cases, while leaving ordinary HTML tags and hydration comments compact.
  • Add hydration, mismatch, namespace, keyed-reordering, uncontrolled-input, focus/ref/event, accessor/Proxy, and hostile streaming-content regressions; add a patch changeset.
  • Add a production raw/gzip/Brotli/comment/carrier audit, a dedicated control-flow fixture, and comment/head-ownership accounting for the three-target TanStack Start production work gate. Document the measurements and remaining follow-ups in docs/ssr-html-payload-audit.md.

Validation

  • env NODE_OPTIONS=--no-experimental-webstorage node node_modules/vitest/vitest.mjs run packages/octane/tests --project octane --project octane-prod --reporter=dot --silent=passed-only — 12,065 core tests across 808 files passed, covering development and production modes.
  • env NODE_OPTIONS=--no-experimental-webstorage node node_modules/vitest/vitest.mjs run --project tanstack-router --project tanstack-router-ssr-query --project tanstack-start --project tanstack-query --project jotai --project rspack-plugin --reporter=dot --silent=passed-only — 297 downstream tests across 41 files passed.
  • ./node_modules/.bin/tsgo --noEmit -p packages/octane/tsconfig.json.
  • pnpm --dir benchmarks/ssr-throughput bench:payload — production builds; equivalent visible markup; raw/gzip/Brotli, hydration-comment, and streaming-carrier measurements.
  • pnpm --filter tanstack-start-bench bench:work against immutable React, Octane, and minimal-Octane production artifacts selected with START_WORK_TARGET_DIR — matching navigation, loaders, status codes, initial state, streamed content, and route payload budgets.
  • Independent production descriptor throughput: 36 alternating paired rounds of five renders; 1.615 ms baseline vs. 1.603 ms optimized per render, with no material regression.
  • Independent baseline parity for descriptor accessors, shape-changing descriptor/array Proxies, iterator evaluation, asynchronous identity, and hydrated server-node identity.
  • env pnpm_config_verify_deps_before_run=warn pnpm sync.
  • pnpm format:check — root-wide check not run.
  • pnpm typecheck — root-wide check not run; the package-scoped source typecheck above passed.
  • pnpm test — root-wide command not run; the 12,065 core and 297 downstream targeted tests above passed.

Risk / follow-ups

  • Hydration ownership changes are intentionally limited to shape-proven cases. Ambiguous or component-bearing values, portals, Suspense/Activity boundaries, adjacent text separators, and unproven head resources keep their existing protocol.
  • Streaming-carrier escaping is security-sensitive; regression coverage verifies mixed-case opening/closing script tokens, tokenizer double-escape sequences, trusted raw HTML, safe reveal, and hydration adoption.
  • The TanStack Start home route still contains 190 <head> comments occupying 2,049 bytes. Its managed-asset ownership attributes may justify a future, explicit core ownership proof, but removing generic head delimiters globally would break foreign-node isolation, cleanup, or multiple-root hydration. This PR deliberately leaves that limitation intact; the measured home route improves only 8,053 → 8,021 raw bytes, while the deferred route improves 10,910 → 10,798 bytes.

Provenance

  • An agent produced this diff (agent-authored)

Note

High Risk
Touches hydration ownership across compiler, server serialization, and client adoption, plus security-sensitive streaming carrier escaping. Incorrect proofs could break hydration identity or allow script-carrier termination.

Overview
Shrinks hydratable SSR HTML by omitting proven-redundant ownership markers while keeping visible markup identical.

The compiler now reuses a same-module single-host component range for eligible keyed @for items, and lets fully specified host-only @if / @switch arms borrow their outer slot range instead of nesting another pair. Descriptor-authored keyed hosts self-delimit only when the already-serialized child is primitive/empty, preserving accessor/Proxy evaluation order and mixed-item behavior.

Streamed Suspense carriers escape only opening/closing script tokens (case-insensitive), so ordinary tags and hydration comments stay compact without weakening parser safety.

Adds a production payload audit, TanStack Start comment accounting, and broad hydration/streaming regressions covering reordering, mismatch recovery, namespaces, and hostile raw HTML.

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

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Aug 11, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review August 11, 2026 22:03
@trueadm
trueadm merged commit 581b8bd into octanejs:main Aug 11, 2026
34 checks passed
trueadm added a commit that referenced this pull request Oct 28, 2026
…tors only

A function inside an array child renders as a body, which
descriptor-list-hydrate pins (#710), so every bundle with an array hole needs
the keyed list's per-item Blocks. Drop the text-only list, the CHILD_LISTS
installer and the createPortalChild compiler proof. Keep the descriptor gates
(ELEMENT_DESCRIPTORS, HOST_DESCRIPTORS) and the hole-free residue fixes. The
reachability check now asserts that a Strong app keeps no descriptor-only
declarations and no descriptor-guarded branch of child-slots.ts or deopt.ts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 28, 2026
…ithout a factory (#2258)

* perf(octane): ship renderable hole value kinds only with their creators

A renderable hole now handles a non-primitive kind only when something in the
bundle can create it. Descriptor factories install ELEMENT_DESCRIPTORS, and
every factory of a list item other than text (descriptors, compiled children
and maps, createPortal) installs the keyed list (CHILD_LISTS). Without one, an
array or iterable child renders as a text list: one Text per leaf, keyed by
index path, adopting the server's per-item ranges when hydrating.

The compiler routes a portal that a module-local component returns to
createPortalChild, which supports only lone portal children. Hole-free bundles
also drop descNeedsBlocks, deoptChildNamespace, childrenIterator and
isHostDescriptor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* perf(octane): keep the keyed child list in every bundle, gate descriptors only

A function inside an array child renders as a body, which
descriptor-list-hydrate pins (#710), so every bundle with an array hole needs
the keyed list's per-item Blocks. Drop the text-only list, the CHILD_LISTS
installer and the createPortalChild compiler proof. Keep the descriptor gates
(ELEMENT_DESCRIPTORS, HOST_DESCRIPTORS) and the hole-free residue fixes. The
reachability check now asserts that a Strong app keeps no descriptor-only
declarations and no descriptor-guarded branch of child-slots.ts or deopt.ts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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