perf(server): avoid base64 fallback for split UTF-8 Flight chunks - #3063
Open
sunflower0305 wants to merge 1 commit into
Open
perf(server): avoid base64 fallback for split UTF-8 Flight chunks#3063sunflower0305 wants to merge 1 commit into
sunflower0305 wants to merge 1 commit into
Conversation
Author
|
For reference, the measurements in the PR description were collected from this blog page, which produced 108 RSC chunks. The source is available in the blog repository. |
RSC embedding decoded each upstream chunk independently, so valid multibyte characters split across chunk boundaries fell back to binary.\n\nKeep a streaming fatal decoder and track undecoded raw bytes so split text remains text while binary errors and incomplete EOF tails stay byte preserving.
sunflower0305
force-pushed
the
perf/split-utf8-flight-chunks
branch
from
August 24, 2026 02:30
4713421 to
0cc0a69
Compare
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
RSC streams can split a valid UTF-8 code point across upstream chunks.
createRscEmbedTransformcurrently decodes each chunk independently with a fatal decoder, so split CJK or emoji bytes are classified as binary and embedded as Base64.This change keeps one streaming fatal decoder for the embed stream and tracks the raw bytes that the decoder has not released yet. Valid split text stays in text chunks, while invalid binary data and incomplete UTF-8 at EOF still use the existing
[3, base64]representation without losing bytes. The decoder is reset after binary fallback so later text can be decoded normally.This follows the streaming decode used by the Next.js Web Flight transport, with explicit raw-byte retention for lossless error and EOF fallback.
Coverage
Application result
Measured on a blog page with 108 RSC chunks:
Verification
vp test run tests/app-ssr-stream.test.ts -t "createRscEmbedTransform raw buffer"vp checkvp run vinext#build