perf: wire node-stream-helpers into render pipeline behind useNodeStreams flag#91583
Open
benfavre wants to merge 3 commits intovercel:canaryfrom
Open
perf: wire node-stream-helpers into render pipeline behind useNodeStreams flag#91583benfavre wants to merge 3 commits intovercel:canaryfrom
benfavre wants to merge 3 commits intovercel:canaryfrom
Conversation
…eams flag Add `experimental.useNodeStreams` config flag that switches the stream operations module (stream-ops.ts) to load native Node.js implementations for hot-path functions: - chainStreams: uses chainNodeStreams (PassThrough-based sequential piping) - streamToBuffer: uses nodeStreamToBuffer (for-await on Node Readable) - streamToString: uses nodeStreamToString (streaming TextDecoder) - renderToFizzStream: uses renderToPipeableStream instead of renderToReadableStream, avoiding web→node conversion overhead in React Complex transform chains (continueFizzStream, prerender continuations) still delegate to the web implementation as a stopgap — the native buffering and data inlining transforms from node-stream-helpers will be wired in a follow-up once the web transform chain is decomposed. Includes the node-stream-helpers module from PR vercel#91580 which provides the underlying native stream utilities. References: vercel#91580, vercel#89566, vercel#90500 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 |
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 |
Replace the web stream delegation in stream-ops.node.ts with a native Node.js Transform pipeline for continueFizzStream. This eliminates the 6-8 web TransformStream objects (plus their internal ReadableStream/ WritableStream pairs) that were created per request — the single most CPU-intensive function in the SSR hot path. New native Node.js Transform equivalents added to node-stream-helpers.ts: - createDeferredSuffixTransformNode (suffix injection after first chunk) - createHeadInsertionTransformNode (server HTML in <head>) - createMoveSuffixTransformNode (move </body></html> to end) - createHtmlDataDplIdTransformNode (data-dpl-id on <html>) - createMetadataTransformNode (icon mark removal + metadata insertion) - createRootLayoutValidatorTransformNode (html/body tag validation) All transforms use: - bindSnapshot() for ALS context propagation - Pre-computed Buffer constants for fast C++ Buffer.indexOf() - Lazy getNodeStream() require for Edge/DCE safety Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Mar 18, 2026
Contributor
Author
Test Verification
All tests run on the |
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
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
Adds
experimental.useNodeStreamsconfig flag that wires our native Node.js stream helpers into the render pipeline:stream-ops.tsbecomes a runtime switcher: when__NEXT_USE_NODE_STREAMSis set, it loadsstream-ops.node.tsinstead ofstream-ops.web.tschainStreams,streamToBuffer,streamToString, andrenderToFizzStream(viarenderToPipeableStream)continueFizzStream, prerender continuations) still delegate to the web implementation as a stopgap — the native buffering and data inlining transforms will be wired in a follow-upnode-stream-helpers.tsmodule from PR feat: add Node.js native stream helpers for render pipeline #91580 which provides the underlying native stream utilitiesMotivation
Profiling shows that WhatWG stream polyfills and the web-to-node conversion layer account for 35%+ of CPU time in SSR workloads (see #89566). By using Node.js native streams on the server, we can eliminate this overhead. This PR establishes the switching infrastructure and implements the easy wins; the complex transform chain migration is a follow-up.
How to enable
What's native vs delegated
chainStreamschainNodeStreamsvia PassThroughstreamToBufferfor awaiton Node ReadablestreamToStringrenderToFizzStreamrenderToPipeableStreamnodeReadableToWebReadable.toWeb()continueFizzStreamcontinueStaticPrerendercontinueDynamic*renderToFlightStreamresumeAndAbortresume()produces web streamsReferences
Test plan
experimental.useNodeStreams: trueand run the app-render test suiterenderToFizzStreamproduces correct HTML viarenderToPipeableStreamchainStreamscorrectly concatenates multiple streamsstreamToBuffer/streamToStringproduce correct output🤖 Generated with Claude Code