Skip to content

perf: skip head-close scan for SSR fragments - #1001

Merged
domgan-oai merged 2 commits into
octanejs:mainfrom
openai-oss-forks:codex/skip-fragment-head-scan-981
Sep 8, 2026
Merged

domgan-oai merged 2 commits into
octanejs:mainfrom
openai-oss-forks:codex/skip-fragment-head-scan-981

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Check whether buffered SSR output is a document before searching it for </head>. Fragment renders with hoisted metadata now prepend the head without scanning the entire body.
  • Add a regression for a fragment containing raw <!-- </head> -->, plus authored and synthesized document-head controls across renderToString, renderToStaticMarkup, and prerender.
  • Add an octane patch changeset. This addresses the spliceHead fragment-scan item in Track V8 performance audit findings across runtime, SSR, universal core, and compiler output #981; the coordination issue remains open.

Why

When a buffered fragment hoists a title or other head resource, spliceHead searched its entire response for </head> even though only a document root can have the closing head it intends to target. On a large response this flattens and scans the whole string. It can also insert the title inside raw fragment content that happens to contain </head> in an HTML comment.

Validation

  • Baseline and candidate production/development source bundles exercised the public buffered string, static markup, and prerender APIs: the baseline misplaced the title inside a fragment comment; the candidate prepends it and preserves the raw comment. headChannel: 'separate' recomposes the candidate folded output. Authored and synthesized document heads retain their placement. A cached compiler emitted both test fixtures with no diagnostics in dev/prod compile modes; the pinned compiler version awaits CI.
  • A source-only stream check compared fragment, authored document, and synthesized-head document responses. Baseline and candidate had identical bytes and SHA-256 in both development and production runtime modes; streaming fragments already bypass this scan.
  • Same-toolchain production source-bundle buffered SSR ABBA probe on Node 26.4.0: 2,400-span fragment (86,648 response bytes), one hoisted title, 1,000 warmups and five 3,000-render rounds per sample, four samples per variant, charging Buffer.byteLength. Median of sample medians: baseline 0.0763 ms/render, candidate 0.0078 ms/render; every response SHA-256 and byte count matched. The no-hoist control was 0.00336 vs 0.00342 ms, and the document control ranged 0.00625–0.00880 vs 0.00759–0.00863 ms. This isolates the fragment scan, not typical application throughput.
  • Scoped Prettier check with base repository settings, git diff --check, direct version generation, package inventory and context-budget checks passed. The production source bundle changed from 100,909 to 100,892 raw bytes.
  • Local pinned Vitest/typecheck and pnpm sync: dependency install stopped when the configured registry returned 403 for pinned @tsrx/[email protected] and @tsrx/[email protected] on successive attempts. Current-head CI covered the pinned toolchain.
  • Current-head CI on 6056abb7497b57d38fa67780a22d74ad6eb8ad5c: all 26 jobs passed, including the corrected SSR regression in both development and production projects, typecheck, lint, browser integration, and provenance. The first head exposed a test-only prerender import error, fixed in the follow-up commit. Cursor Bugbot passed with no review comments.

Risk / follow-ups

  • Document renders with hoisted metadata now perform a prefix document check before their closing-head search. Document control timings overlapped across variants; their throughput effect is unresolved at this sample size. The changed fragment path is buffered; streaming output was checked for byte identity.

Provenance

  • An agent produced this diff (agent-authored)

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


Note

Low Risk
Scoped to buffered SSR head splicing; document behavior is preserved and streaming was byte-identical in validation.

Overview
Buffered SSR fragments with hoisted metadata no longer search the full response for </head>. spliceHead now uses a prefix isDocumentRoot check: non-document bodies prepend hoisted head markup (or return unchanged when empty) without scanning, which avoids wasted work on large fragments and stops false matches when raw HTML contains </head> (e.g. inside a comment).

Document renders are unchanged in intent—they still splice before an existing </head> or synthesize a <head> after <html>—with a small control-flow simplification after the early fragment exit.

Tests cover the comment regression, headChannel: 'separate' recomposing folded output, and metadata placement for authored vs synthesized document heads across renderToString, renderToStaticMarkup, and prerender. An octane patch changeset records the fix.

Reviewed by Cursor Bugbot for commit 8f6e2a6. 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 Sep 8, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review September 8, 2026 20:24
@domgan-oai
domgan-oai merged commit ab32364 into octanejs:main Sep 8, 2026
31 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.

1 participant