Skip to content

perf(octane): reuse serialized streamed shell styles - #2094

Merged
trueadm merged 1 commit into
octanejs:nextfrom
openai-oss-forks:codex/next-ssr-shell-style-reuse
Oct 15, 2026
Merged

trueadm merged 1 commit into
octanejs:nextfrom
openai-oss-forks:codex/next-ssr-shell-style-reuse

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Reuse the shell pass's serialized scoped styles when streaming the initial HTML. The pass already produced this exact markup; serializing its entries again duplicated work and maintained a second escaping/nonce path. Seed the emitted-style set from the same entries so later waves still deduplicate correctly.

Validation

  • pnpm format:check (scoped format check passed)
  • pnpm typecheck (scoped typecheck passed)
  • pnpm test (full workspace suite not run locally)
  • targeted tests: 234 SSR/streaming tests passed in development and production compile modes; deliberately removing shell styles failed the existing wave test, then it passed after restoration.
  • Perf review: scan found zero candidates. runStream runs once per streamed request; this removes one style serialization per shell entry and adds no hot record fields, DOM work, or scheduling. A matched production probe reduced serialization calls for 0/1/3 styles from 0/2/6 to 0/1/3 with identical complete HTML hashes. The isolated server-entry bundle changed −123 raw / +15 gzip bytes. End-to-end latency and a complete consumer bundle were not measured.
  • Concise-code: runtime source +2/−13; reuse the existing pass output. Keeping a second serializer was rejected because it duplicates escaping and nonce behavior. Independent complexity review found no remaining unjustified complexity.

Risk / follow-ups

The byte measurement is an isolated server entry, not a complete application bundle. Current-head CI provides broader coverage.

Provenance

  • An agent produced this diff (agent-authored)

Codex task · host com-79386.


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


Note

Low Risk
Localized SSR streaming optimization with identical markup intent; dedup keys are unchanged so wave behavior should stay the same.

Overview
Streamed shell output now reuses the shell pass’s already-serialized scoped styles instead of walking pass.cssEntries again to build <style> tags (escaping, nonce, data-octane hashes).

leadingStyles is set directly from pass.css, and emittedCss is seeded from the same entry keys so later streaming waves still skip styles already sent on the shell head fold.

Reviewed by Cursor Bugbot for commit caa2b32. 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 Oct 15, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review October 15, 2026 14:54
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No byte growth, no added work, and no timing changes beyond ±3%.

Compares c4cbd556e, the merge commit's first parent with 93283c9b3 on the same runner. Any increase in a js-framework work counter fails this check; byte changes are a report. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.600 2.717 ±0.0% −4.0% … +1.0% ⚪ within noise
octane-tsrx replace 8.317 8.508 +2.0% −4.2% … +4.6% ⚪ within noise
octane-tsrx add 2.100 2.150 ±0.0% ±0.0% … +4.1% ⚪ within noise
octane-tsrx update 0.093 0.095 −0.3% −2.7% … +1.9% ⚪ within noise
octane-tsrx select 0.005 0.005 −0.0% −2.1% … +1.1% ⚪ within noise
octane-tsrx swap 0.017 0.017 +1.2% −1.2% … +4.0% ⚪ within noise
octane-tsrx remove 0.015 0.016 +0.4% −2.5% … +3.4% ⚪ within noise
octane-tsrx runlots 23.875 22.958 +2.5% −4.9% … +6.8% ⚪ within noise
octane-tsrx select_lots 0.007 0.007 −1.4% −9.1% … +0.3% ⚪ within noise
octane-tsrx clear 53.692 53.575 −3.0% −9.4% … +3.8% ⚪ within noise
octane-jsx run 4.017 3.758 −2.7% −8.7% … +2.9% ⚪ within noise
octane-jsx replace 16.850 16.067 −3.2% −6.9% … +1.6% ⚪ within noise
octane-jsx add 6.750 7.475 +5.9% −2.9% … +22.0% ⚪ within noise
octane-jsx update 0.317 0.313 +0.5% −3.6% … +5.2% ⚪ within noise
octane-jsx select 0.178 0.181 +0.8% −1.3% … +3.2% ⚪ within noise
octane-jsx swap 0.221 0.198 −1.5% −6.0% … +1.9% ⚪ within noise
octane-jsx remove 0.239 0.211 −4.2% −13.9% … +0.4% ⚪ within noise
octane-jsx runlots 50.600 56.825 +3.5% −8.3% … +18.4% ⚪ within noise
octane-jsx select_lots 4.644 5.083 +3.0% −6.1% … +19.7% ⚪ within noise
octane-jsx clear 97.725 96.933 +8.7% −9.0% … +24.1% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 93 measured values.

Public-import reachability bundles (bytes)

No changes across 123 measured values.

@trueadm trueadm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving. The change is small and behaves the same.

Correctness. runFullFramedPass builds pass.css (runtime.server.ts ~9300) with the same <style data-octane=…> serialization the shell loop repeated:

  • the same per-sheet nonce versus the request's nonceAttr;
  • the same escapeEntireInlineStyleContent;
  • the same iteration order over cssEntries.

runStream passes the same nonceAttr into that pass (line 11859). pass is reassigned on every root-suspension retry, but leadingStyles and emittedCss are both read from the final pass, so they still agree. Between that pass and line 12147 only synchronous code runs, and the CSS collector has already been restored by restoreAmbient, so nothing can add a sheet to cssEntries that pass.css lacks. Seeding emittedCss from cssEntries.keys() keeps the dedupe at line 12329 for later waves.

Tests. No new test, which is reasonable for an output-identical refactor. Your mutation check (dropping the shell styles fails the existing wave test) shows the path is covered.

Numbers (benchmark on caa2b32, run 38755649764):

  • All 64 work counters are unchanged.
  • All 93 application and 123 reachability byte values are unchanged, as expected for server-only code.
  • All 20 timings are within noise.

The isolated server-entry figure in the body (−123 raw / +15 gzip) isn't a client cost. The win is one fewer serialization per shell style, which the probe counted (0/2/6 → 0/1/3 calls).

CI on the current head is fully green: 30 pass, 6 skipped matrix placeholders.

Reviewed with Claude Code

@trueadm
trueadm merged commit 5370a31 into octanejs:next Oct 15, 2026
77 of 80 checks passed
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