perf: merge head-related stream transforms to reduce pipeline overhead#91575
Open
benfavre wants to merge 1 commit intovercel:canaryfrom
Open
perf: merge head-related stream transforms to reduce pipeline overhead#91575benfavre wants to merge 1 commit intovercel:canaryfrom
benfavre wants to merge 1 commit intovercel:canaryfrom
Conversation
Introduces `createUnifiedHeadTransform` that fuses three separate TransformStream objects into one: 1. `createHtmlDataDplIdTransformStream` — inserts `data-dpl-id` on `<html>` 2. `createMetadataTransformStream` — handles icon-mark replacement 3. `createRootLayoutValidatorStream` — validates `<html>` / `<body>` presence All three operate on the first few chunks then become pure pass-through. By merging them, we eliminate 2 TransformStream allocations per request (each carrying its own ReadableStream + WritableStream + internal queues + backpressure bookkeeping). Applied across all five `continue*` functions: - `continueFizzStream`: 8 → 6 transforms (up to) - `continueDynamicPrerender`: 5 → 4 transforms - `continueStaticPrerender`: 6 → 5 transforms - `continueStaticFallbackPrerender`: 7 → 6 transforms - `continueDynamicHTMLResume`: 6 → 5 transforms The unified transform preserves exact behavioral parity: - dplId insertion triggers on first `<html` tag, then skips - Metadata icon-mark uses the same chunkIndex-aware first-chunk logic - Root layout validator inspects chunks and emits error in flush() - Fast-path flag skips all searches once every operation completes Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
Contributor
Author
Test Verification
All tests run on the |
Contributor
Author
Performance ImpactProfiling setup: Node.js v25.7.0, Before (canary):
After (this PR):
|
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Merge three head-related
TransformStreamobjects into a singlecreateUnifiedHeadTransformto reduce stream pipeline overhead.Problem
continueFizzStreamchains up to 8 separate TransformStream objects per request. Each creates internal ReadableStream + WritableStream + queues + backpressure management. Stream operations account for 50%+ of non-React CPU time in production profiles.Three of these transforms (
createHtmlDataDplIdTransformStream,createMetadataTransformStream,createRootLayoutValidatorStream) do one-time work on the first few chunks then become pure pass-through. Merging them eliminates 2 TransformStream objects per request.Changes
createUnifiedHeadTransform()combines deployment ID insertion, metadata icon-mark handling, and root layout validation into a single transform with anallDonefast-path flagcontinue*functions to use the unified transformcontinueFizzStream8→6,continueDynamicPrerender5→4,continueStaticPrerender6→5, etc.Performance Context
CPU profile breakdown (30 concurrent, 20s sustained load):
The remaining stream overhead is addressable by switching to Node.js native streams (PR #91583).
Test plan
🤖 Generated with Claude Code