Skip to content
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 10 commits into from
May 28, 2022
Merged

Commits on May 27, 2022

  1. [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.
    gnoff committed May 27, 2022
    Configuration menu
    Copy the full SHA
    96fad9f View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6393401 View commit details
    Browse the repository at this point in the history
  3. [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
    gnoff committed May 27, 2022
    Configuration menu
    Copy the full SHA
    a9e72bf View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    d0660fe View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    3030aec View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    3f61057 View commit details
    Browse the repository at this point in the history
  7. flow and lint

    gnoff committed May 27, 2022
    Configuration menu
    Copy the full SHA
    f7c4b86 View commit details
    Browse the repository at this point in the history
  8. cleanup flow some more

    gnoff committed May 27, 2022
    Configuration menu
    Copy the full SHA
    19c76fa View commit details
    Browse the repository at this point in the history
  9. more flow refinement

    gnoff committed May 27, 2022
    Configuration menu
    Copy the full SHA
    fc76c7f View commit details
    Browse the repository at this point in the history
  10. cleanup ReactNoopServer

    gnoff committed May 27, 2022
    Configuration menu
    Copy the full SHA
    277beb8 View commit details
    Browse the repository at this point in the history