Skip to content

perf: speed up server-rendered HTML escaping - #629

Merged
trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:feat/ssr-loop-array-materialization
Aug 7, 2026
Merged

trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:feat/ssr-loop-array-materialization

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

  • Investigate phase four of Performance roadmap: targeted updates, JSX lowering, DOM mounting, SSR, reconciliation, and bundle budgets #611 against untouched production SSR builds before changing server-loop behavior.
  • Reject array-snapshot removal: the existing Array.from copy consumes approximately 0.64% of sampled allocated bytes and 0.025% of total render time, while alternatives that preserve custom iterators, proxies, getter ordering, eager mutation snapshots, and suspension were 6–20 times slower.
  • Preserve the exact eager array snapshot and instead replace the three dirty-text regular-expression escaping passes with equivalent native literal replacement passes.
  • Add consumer-visible coverage for hostile markup, pre-escaped entities, Unicode/surrogates, coercion and reentrant rendering, errors, streaming, and hydration adoption.
  • Extend the existing SSR throughput benchmark with an untimed deterministic gate requiring zero regex escaping passes, exactly one 10,000-item eager array snapshot, and byte-identical rendered HTML.

Same-session balanced production measurements:

Measurement Upstream This change
Escape-heavy SSR, 120 balanced renders 3.7462 ms 2.9676 ms (-20.8%)
Sampled allocation volume 249.04 MB 213.98 MB (-14.1%)
Compiled application SSR, 160 balanced pairs 1.0161 ms 1.0106 ms (neutral)
Streaming SSR, 56 balanced pairs 1.3967 ms 1.3950 ms (neutral)
Server production bundle gzip baseline +14 bytes
Eager array snapshot 1 copy / 10,000 entries 1 copy / 10,000 entries

The compiled, streaming, and escaped HTML outputs remain byte-identical.

Part of #611.

Validation

  • pnpm format:check
  • pnpm typecheck
  • pnpm test
  • targeted tests: the exhaustive Octane core development suite (401 files; 5,937 tests) and production suite (365 files; 4,876 tests), totaling 10,813 passing tests.
  • ./node_modules/.bin/tsgo --noEmit -p packages/octane/tsconfig.json.
  • ./node_modules/.bin/tsgo --noEmit -p packages/octane/typetests/tsconfig.json.
  • CONFIGS=escape,deopt,waterfall,parallel node benchmarks/ssr-throughput/run.mjs 0.1 --quick --no-build across seven Octane SSR scenarios, including the new deterministic work gate.
  • TARGETS=octane node benchmarks/streaming-ssr/run.mjs 3 --no-build across staggered and all-fast modes.
  • pnpm sync.
  • 120-render production ABBA, 160-pair ordinary SSR control, 56-pair streaming control, allocation sampling, and exact HTML hashes.

Risk / follow-ups

  • The clean-text guard, attribute escaper, iterator protocol, snapshot timing, generated compiler output, client bundle, and hydration markers are unchanged.
  • A deliberately broken < escaping implementation makes the new buffered, hostile-markup, and streamed-output tests fail; restoring it makes both compile modes pass.
  • The latest upstream lockfile contains Preact and Ripple packages unavailable from the configured package registry. Validation therefore uses the exact locked, cached Octane dependencies and faithful repository-root core development/production configurations. Exactly two unrelated installed-binding discovery suites (external-hook-slot.test.ts and register-hook.test.ts) are excluded because their optional packages cannot be installed; every SSR, security, streaming, hydration, compiler, and runtime suite remains included. Full cross-framework workspace checks are explicitly not claimed.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Touches security-sensitive HTML escaping on the server; behavior is heavily tested and benchmark-gated, but any escaper regression could affect XSS safety.

Overview
Server escapeHtml still uses a single pre-scan on clean text; when escaping is needed, the three global-regex .replace passes are swapped for String.prototype.replaceAll with literal targets (&, <, >). The attribute escaper, list snapshot behavior, and streaming/hydration paths are intentionally unchanged.

The escape-heavy SSR benchmark gains a post-run work gate that re-renders under instrumentation: it fails if HTML escaping still goes through the old regex replacement pattern, if the 10k-item list is not snapshotted exactly once via Array.from, or if the response body differs. README and changeset document the perf goal and preserved semantics.

SSR tests expand coverage for escaped text across buffered/static markup, coercion and errors, streaming output, and hydration adopting server nodes—without changing production behavior beyond the escaper implementation.

Reviewed by Cursor Bugbot for commit 13a0de5. 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 7, 2026
@trueadm
trueadm marked this pull request as ready for review August 7, 2026 20:32
@trueadm
trueadm merged commit d69ab86 into octanejs:main Aug 7, 2026
53 checks passed
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 7, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 7, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 7, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 7, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 7, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 7, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
jonkwheeler pushed a commit to jonkwheeler/octane that referenced this pull request Aug 8, 2026
leonidaz pushed a commit that referenced this pull request Aug 10, 2026
* docs(packaging): plan CommonJS package conditions

* feat(packaging): add CommonJS graph builder

* fix(packaging): parse CommonJS graphs with esbuild

* feat(octane): publish CommonJS runtime entries

* feat(bindings): publish CommonJS runtime graphs

* test(packaging): exercise packed CommonJS consumers

* chore(release): record CommonJS package conditions

* test(packaging): run CommonJS tarball canary

* test(packaging): compare ESM and CommonJS parity

* fix(review): guard CommonJS output deletion

* fix(review): reject lossy CommonJS transforms

* feat(packaging): compile TSRX CommonJS graphs

* perf(packaging): reuse TSRX compilation work

* feat(packages): support callable CommonJS defaults

* fix(packages): recognize TSRX CommonJS roots

* perf: speed up server-rendered HTML escaping (#629)

* perf: skip unchanged conditional keyed rows (#628)

* perf: skip unchanged conditional keyed rows

* fix: exclude Activity boundaries from keyed row memoization

* fix(ci): prevent usehooks hydration timeout

* fix(ci): refresh React parity evidence hashes

* perf: reuse bounded keyed-reorder scratch storage (#630)

* perf: add minimal-import bundle reachability budgets (#631)

* perf: add minimal-import bundle reachability budgets

* fix: register reachability benchmark with MCP server

* fix: preserve side-effect-only bootstrap entrypoints (#633)

* perf: cache stable renderable regions and prune sync warming (#634)

* perf: cache stable renderable regions and prune sync warming

* fix: preserve uppercase-prefixed custom hook state

* fix(benchmarks): remove js-framework DOM node metrics (#636)

* fix(bindings): classify production bundle side effects (#637)

* feat: enable React Compiler across framework benchmarks (#639)

* perf: reduce core runtime and compiled application bundles (#638)

* Version Packages (#601)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(commonjs): fail closed on authored .tsrx modules

Refuse compiling .tsrx into CommonJS packaging output so published packages keep source for consumers to compile.

Co-authored-by: Cursor <[email protected]>

* fix(commonjs): restore published require export conditions

Re-apply the CommonJS require maps for octane and the binding packages after the main merge dropped them.

Co-authored-by: Cursor <[email protected]>

* fix(commonjs): order require before default and wire binding prepack

Put import/require ahead of default in octane publishConfig.exports so Node does not always pick the ESM graph, and run build:cjs from prepack for the binding packages that advertise dist/cjs.

Co-authored-by: Cursor <[email protected]>

* fix(compiler): discover source packages without a CommonJS build

require.resolve failed on prepack-only dist/cjs entries in CI, so Vite
source discovery skipped Base UI and nested bindings. Fall back to the
installed package manifest when the require target is missing.

Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: domgan-oai <[email protected]>
Co-authored-by: Dominic Gannaway <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Cursor <[email protected]>
trueadm added a commit that referenced this pull request Aug 28, 2026
* feat(bindings): port react-transition-group

* fix(bindings): address transition parity feedback (#487)

* fix(bindings): make group updates synchronous (#487)

* fix(bindings): register transition group integrations (#487)

* fix(bindings): refresh transition parity evidence (#487)

* fix(bindings): guard null transition refs (#487)

* fix(bindings): format transition parity inventory (#487)

* fix(react-transition-group): preserve transition state

* fix(ci): format TransitionGroup source

* fix(ci): refresh transition parity lock hash

* docs: refresh package inventory

* docs: refresh binding parity gaps

* docs: refresh binding status

* fix(react-transition-group): refresh stable child flags

* chore(evals): refresh transition group corpus

* fix(ci): refresh transition parity evidence

* fix(ci): format transition parity inventories

* feat(react-select): add foundation and default components

* feat(react-select): port managed option hooks

* feat(react-select): port Select and composed entrypoints

* feat(react-select): add nonce and public type parity

* feat(react-select): match menu placement and keyboard navigation

* feat(react-select): match accessibility and scroll behavior

* feat(react-select): match touch interaction behavior

* feat(react-select): match multi-value navigation

* feat(react-select): match input and form events

* feat(react-select): match pointer selection behavior

* feat(react-select): match mount focus behavior

* feat(react-select): complete exact binding

* fix(react-select): register migration rewrites (#541)

* fix(react-select): enforce public type parity

* chore(ci): refresh react-parity evidence after main merge

Regenerate lockfile hashes and inventory for react-select.

Co-authored-by: Cursor <[email protected]>

* chore(ci): refresh react-parity evidence after main merge

Regenerate lockfile hashes and inventory for react-select.

Co-authored-by: Cursor <[email protected]>

* chore(ci): refresh react-parity evidence after main merge

Regenerate lockfile hashes and inventory for react-select.

* perf: speed up server-rendered HTML escaping (#629)

* perf: skip unchanged conditional keyed rows (#628)

* perf: skip unchanged conditional keyed rows

* fix: exclude Activity boundaries from keyed row memoization

* fix(ci): prevent usehooks hydration timeout

* fix(react-select): resolve Bugbot keyed-list and selection regressions

Always call setValue on single-select reselection, merge Fade innerProps,
and add stable keys for menu, form, and animated value-container children.

Co-authored-by: Cursor <[email protected]>

* fix(react-select): pass animated value children without Fragment wrappers

Octane Children.toArray does not flatten Fragment descriptors, so MultiValueContainer could not clone transition props onto MultiValue and Placeholder children.

Co-authored-by: Cursor <[email protected]>

* fix(react-select): pass inspectable animated value children

Restore the needsInspectableValueChildren path so TransitionGroup receives an enumerable children array instead of a compiler opaque block, without Fragment wrappers that Children.toArray cannot flatten.

Co-authored-by: Cursor <[email protected]>

* test(react-transition-group): scaffold upstream parity lanes

Run the pinned React suite unchanged and separate adapted parity evidence from ordinary Octane conformance coverage.

Co-authored-by: Cursor <[email protected]>

* test(react-select): add pristine upstream Jest lane

Run the vendored react-select suites unchanged as a required parity oracle,
drop whole-project parity ownership so repo-authored tests stay ordinary, and
refresh neighboring vitest.config.js evidence hashes after the main merge.

Co-authored-by: Cursor <[email protected]>

* test(react-transition-group): complete adapted upstream suite

Port every applicable upstream runtime case one-for-one so the adapted lane now provides exhaustive parity evidence with no pending dispositions.

Co-authored-by: Cursor <[email protected]>

* test(react-select): start adapted upstream suite

Port the smaller upstream suites into a verified Octane lane and account for every remaining pristine identity with fail-closed controls.

Co-authored-by: Cursor <[email protected]>

* test(react-select): adapt core Select behavior

Port 102 upstream Select cases covering props, filtering, inputs, callbacks, accessibility, and interactions, reducing the unadapted inventory to 115 identities.

Co-authored-by: Cursor <[email protected]>

* test(react-transition-group): address parity review feedback

Strengthen adapted lifecycle scenarios and keep parity evidence mapped to the files that execute each upstream case.

Co-authored-by: Cursor <[email protected]>

* test(react-select): expand Select upstream coverage

Adapt 66 more Select cases across keyboard navigation, callbacks, forms, accessibility, custom components, and value handling, leaving 49 pristine identities pending.

Co-authored-by: Cursor <[email protected]>

* test(react-select): complete adapted upstream suite

Port the remaining one-for-one adapted cases to 248 of 255 pristine
identities, keep seven Select blockers fail-closed with rationales, and
refresh the parity inventories and hashes for the review feedback.

Co-authored-by: Cursor <[email protected]>

* test(react-select): stabilize StateManaged snapshot ids

Move the defaults snapshot before other mounts so instance ids stay at
react-select-1 regardless of suite filtering or test order.

Co-authored-by: Cursor <[email protected]>

* fix(react-select): match upstream focus and clear behavior

Co-authored-by: Cursor <[email protected]>

* fix(react-select): mark parity provenance verified

Unverified provenance left required React parity lanes validate-only; flip to verified so CI executes them.

Co-authored-by: Cursor <[email protected]>

* fix(react-transition-group): add type lanes for verified parity

Absent upstream type suites still require repo-authored pristine-types and adapted-types evidence before verification can be verified; add consumer-shaped typetests and refresh lockfile hashes.

Co-authored-by: Cursor <[email protected]>

* fix(react-transition-group): restore adapted upstream oracles

Address leonidaz parity review: node-env SSR adapted project, silent
cleanup console spy, mid-appear null child, childFactory reentry,
appear checkpoint, and full SwitchTransition callback traces.

Co-authored-by: Cursor <[email protected]>

* fix(react-select): address parity inventory review

Split the transition-group SSR adaptation into its own required lane, inventory
the three canonical react-select skips as not-applicable, classify Select.test.ts
under fail-closed discovery, and reconcile UPSTREAM.md with the verified counts.

Co-authored-by: Cursor <[email protected]>

* fix(react-select): close leonidaz parity control gaps

Add assertion-group type parity verifiers and typetest ledger coverage for
react-select and react-transition-group, record exact oracle versions, and
drop Vitest wrappers around the direct jest-full pristine lanes.

Co-authored-by: Cursor <[email protected]>

* fix(select): close type-parity controls and drop react prefix

Verify mapped typetest fixtures belong to the pristine/adapted compiler
programs, record the exact @types/react type-oracle pins, and rename the
Octane package to @octanejs/select per maintainer naming guidance.

Co-authored-by: Cursor <[email protected]>

* chore: refresh parity hashes after select rename and main merge

Co-authored-by: Cursor <[email protected]>

* fix(select): route differential tests to react-parity and pin type oracle

Move the six react-octane-differential SSR suites into a dedicated
select-differential Vitest project under testExecution.group react-parity,
and replace catalog:default @types/react pins with literal 19.2.17/19.2.3.

Co-authored-by: Cursor <[email protected]>

* fix(select): reconcile multi-value focus and key inspectable children

Match upstream focusedValue remapping on value updates and give the
animated ValueContainer path stable keys without breaking MultiValue
child inspection.

Co-authored-by: Cursor <[email protected]>

* fix(select): flatten keyed fragments in animated ValueContainer

Unwrap inspectable ValueContainer's keyed Fragment slots before
TransitionGroup and MultiValueContainer inspect child types.

Co-authored-by: Cursor <[email protected]>

* fix(select): preserve animated child identities (#541)

- retain fragment and inner child keys when flattening inspectable children
- cover animated single-select value and input rendering

Note: pre-existing typecheck failures in packages/select/src/animated/transitions.tsrx were not addressed by this PR.

* chore: format refreshed parity evidence

* fix(select): validate without Node ambient types

* fix(select): register browser suite in heavy CI

* chore: refresh eval corpus hashes

* fix(select): reconcile async state transactionally

* chore: refresh merged parity evidence

* fix(select): address parity review findings

---------

Co-authored-by: Cursor <[email protected]>
Co-authored-by: domgan-oai <[email protected]>
Co-authored-by: Dominic Gannaway <[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