[Fizz/Flight] Don't start writing to the stream if it's already full#22726
[Fizz/Flight] Don't start writing to the stream if it's already full#22726devknoll wants to merge 1 commit intofacebook:mainfrom devknoll:x-early-exit-stream
Conversation
|
Comparing: 2b77ab2...8b6d828 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
|
I don't have context on this and Seb is out for a bit. Is this blocking you? |
|
ping @sebmarkbage |
sebmarkbage
left a comment
There was a problem hiding this comment.
Yea, this makes sense. The goal is that we'd ideally own the whole stream and at that point it'd be unnecessary to check this. At some point we might want to revert this for that reason. For now it's not practical to let React own the stream.
| destination.cork(); | ||
| export function beginWriting(destination: Destination): boolean { | ||
| // Older versions of Node don't have this. | ||
| if (destination.writableNeedDrain !== true) { |
There was a problem hiding this comment.
How about writableLength >= writableHighWaterMark? It goes back a little further in terms of Node versions. That's what write() practically returns, and what is checked before needDrain is set to true. It's also how we implement that for web streams.
Summary
Currently, React will always write something when flushing completed work, because it never checks if the stream is full until after writing. With this change, React will bail out early and continue buffering if we know we're still waiting for the stream to drain, so that we only write the most up-to-date data to the stream.
How did you test this change?
Existing tests pass. Could probably use a test to validate full behavior.