Repository navigation
perf(octane): reuse serialized streamed shell styles - #2094
Conversation
Benchmark report🟢 No byte growth, no added work, and no timing changes beyond ±3%. Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
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
left a comment
There was a problem hiding this comment.
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
nonceversus the request'snonceAttr; - 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
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)runStreamruns 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.Risk / follow-ups
The byte measurement is an isolated server entry, not a complete application bundle. Current-head CI provides broader coverage.
Provenance
agent-authored)Codex task · host
com-79386.Need help on this PR? Tag
@codesmith-botwith 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.cssEntriesagain to build<style>tags (escaping, nonce,data-octanehashes).leadingStylesis set directly frompass.css, andemittedCssis 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.