-
Notifications
You must be signed in to change notification settings - Fork 50.9k
[Fizz] Reduce chunk push overhead in HTML serialization #36139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,8 +222,11 @@ export function typedArrayToBinaryChunk( | |
|
|
||
| export function byteLengthOfChunk(chunk: Chunk | PrecomputedChunk): number { | ||
| return typeof chunk === 'string' | ||
| ? Buffer.byteLength(chunk, 'utf8') | ||
| : chunk.byteLength; | ||
| ? chunk.length // Fast path: .length === byte length for ASCII (99%+ of HTML output). | ||
| : // For multi-byte chars this slightly underestimates, which is fine | ||
| // because byteSize is only used for heuristic decisions (outlining | ||
| // threshold and progressive chunk sizing). | ||
| chunk.byteLength; | ||
|
Comment on lines
+225
to
+229
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change should have broken something in ReactFlightServer. Suggests that we have some untested serialization path with large string serialization. Even if the rationale was true though we can't land this change because the layering implies you get back an accurate byteLength. We'd have to rename to getApproximateByteLength etc... Unless this is like the entirety of the perf win it doesn't seem worth the effort to rewrite the parts that use this length for approximating heuristics so let's just drop it. If you want to see what would be broken by this check out |
||
| } | ||
|
|
||
| export function byteLengthOfBinaryChunk(chunk: BinaryChunk): number { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason it was written the way it was before is we try to avoid branching on hot paths as much as possible. In this case you are adding an extra if check to every element that has non string children because we check the innerHTML twice instead of once.
There is probably a more dramatic refactor that could avoid the extra conditional and still allow for the avoidance of the extra chunk.