-
Notifications
You must be signed in to change notification settings - Fork 47k
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
[Fizz] Improve text separator byte efficiency #24630
Merged
Merged
Commits on May 27, 2022
-
[Fizz] Improve text separator byte efficiency
Previously text separators were inserted following any Text node in Fizz. This increases bytes sent when streaming and in some cases such as title elements these separators are not interpretted as comment nodes and leak into the visual aspects of a page as escaped text. The reason simple tracking on the last pushed type doesn't work is that Segments can be filled in asynchronously later and so you cannot know in a single pass whether the preceding content was a text node or not. This commit adds a concetp of TextEmbedding which provides a best effort signal to Segments on whether they are embedded within text. This allows the later resolution of that Segment to add text separators when possibly necessary but avoid them when they are surely not. The current implementation can only "peek" head if the segment is a the Root Segment or a Suspense Boundary Segment. In these cases we know there is no trailing text embedding and we can eliminate the separator at the end of the segment if the last emitted element was Text. In normal Segments we cannot peek and thus have to assume there might be a trailing text embedding and we issue a separator defensively. This should be rare in practice as it is assumed most components that will cause segment creation will also emit some markup at the edges.
Configuration menu - View commit details
-
Copy full SHA for 96fad9f - Browse repository at this point
Copy the full SHA 96fad9fView commit details -
Configuration menu - View commit details
-
Copy full SHA for 6393401 - Browse repository at this point
Copy the full SHA 6393401View commit details -
[Fizz] Improve separator efficiency when flushing delayed segments
The method by which we get segment markup into the DOM differs depending on when the Segment resolves. If a Segment resovles before flushing begins for it's parent it will be emitted inline with the parent markup. In these cases separators may be necessary because they are how we clue the browser into breakup up text into distinct nodes that will later match up with what will be hydrated on the client. If a Segment resolves after flushing has happened a script will be used to patch up the DOM in the client. when this happens if there are any text nodes on the boundary of the patch they won't be "merged" and thus will continue to have distinct representation as Nodes in the DOM. Thus we can avoid doing any separators at the boudnaries in these cases. After applying these changes the only time you will get text separators as follows * in between serial text nodes that emmit at the same time - these are necessary and cannot be eliminated unless we stop relying on the browser to automatically parse the correct text nodes when processing this HTML * after a final text node in a non-boundary segment that resolves before it's parent has flushed - these are sometimes extraneous, like when the next emitted thing is a non-Text node. In all other cases text separators should be omitted which means the general byte efficiency of this approach should be pretty good
Configuration menu - View commit details
-
Copy full SHA for a9e72bf - Browse repository at this point
Copy the full SHA a9e72bfView commit details -
Configuration menu - View commit details
-
Copy full SHA for d0660fe - Browse repository at this point
Copy the full SHA d0660feView commit details -
Configuration menu - View commit details
-
Copy full SHA for 3030aec - Browse repository at this point
Copy the full SHA 3030aecView commit details -
Configuration menu - View commit details
-
Copy full SHA for 3f61057 - Browse repository at this point
Copy the full SHA 3f61057View commit details -
Configuration menu - View commit details
-
Copy full SHA for f7c4b86 - Browse repository at this point
Copy the full SHA f7c4b86View commit details -
Configuration menu - View commit details
-
Copy full SHA for 19c76fa - Browse repository at this point
Copy the full SHA 19c76faView commit details -
Configuration menu - View commit details
-
Copy full SHA for fc76c7f - Browse repository at this point
Copy the full SHA fc76c7fView commit details -
Configuration menu - View commit details
-
Copy full SHA for 277beb8 - Browse repository at this point
Copy the full SHA 277beb8View commit details
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.