perf: stream HTML chunks through lol_html without full-document buffering#321
Draft
perf: stream HTML chunks through lol_html without full-document buffering#321
Conversation
…ring HtmlRewriterAdapter previously accumulated the entire request body before instantiating the HtmlRewriter, then processed it in a single pass. This caused TTFB to be gated on receiving the last byte of the origin response. Switch to lol_html's incremental streaming API by creating the HtmlRewriter eagerly in new() with a shared RcVecSink output buffer. Each process_chunk call writes directly to the live rewriter and drains whatever output lol_html has produced so far, so bytes flow downstream as soon as the parser can emit them (typically everything up to the first matched element fires immediately). Also fix process_gzip_to_gzip to delegate to process_through_compression (like deflate and brotli already did) instead of decompressing the entire body into a Vec before processing. Update tests: intermediate chunks may now carry data, so assertions collect across all chunks rather than asserting intermediates are empty.
Collaborator
|
@jevansnyc this will break the RSC Next.js integration for HTML responses that contain self.__next_f.push() scripts with origin URLs. The post-processing phase that rewrites RSC payloads will receive only the tail of the document instead of the full output, causing placeholder strings to leak into the response and breaking React hydration. Possible fix The HtmlWithPostProcessing wrapper needs to accumulate all output across chunks when post-processors are registered, then run post-processing on the complete document at is_last=true. Alternatively, the post-processing could be restructured to work incrementally — but that's a larger change given the cross-script T-chunk combining logic. |
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
What this does not change yet (follow-up)
The full TTFB improvement requires two more changes tracked for a follow-up PR:
Test plan