Repository navigation
perf(markdown): parse a streaming reply in settled chunks (#1475) - #1483
Merged
currentbits merged 4 commits intoOct 5, 2026
Merged
Conversation
The streaming assistant message was re-parsed as a whole on every push, O(n^2) over one long answer. Split it at blank lines before column-0 blocks outside fences; each settled chunk is a memoized parse, so a push re-parses only the last chunk. Lists that continue across blank lines, raw-HTML-only chunks, link/footnote definitions and blank-spanning HTML blocks don't split. Non-streaming messages stay one parse. Bench (jsdom, 45 KB at 4 pushes/s): 4.7 s -> 0.3 s total render; per push at 45 KB 83-89 ms -> 3.6-4.5 ms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dented code (#1475) A fuzz pass found two mismatches with the one-shot render: - an HTML block starting mid-chunk swallowed a fence line, desyncing the fence tracker. Any line starting with raw HTML now keeps one parse (3 of 600 sampled real replies have one). - a boundary right after indented code (tab or 4+ spaces) mis-parsed a following non-1 ordered item. No boundary after an indented line now. Adds a seeded 10k-mix fuzz test comparing chunked vs one-shot markup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… load Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
2 tasks
…mit (#1475) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 6, 2026
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.
Part of #1475, renderer finding 4 (markdown was re-parsed on every streamed push).
What changed
While a reply streams,
MarkdownBodysplits it into chunks at settled block boundaries (markdownChunks). Each chunk is a memoizedReactMarkdown, so a push re-parses only the last, still-growing chunk. Finished messages are one parse, as before, so the final render is exactly the old one.The splitter is conservative:
Measured (
test/perf/markdownStream.bench.tsx, jsdom, 100 pushes of a 45 KB reply):Verified independently. The check in each case:
renderToStaticMarkupof the chunked render must equal the one-shot render.3., which are fixed in 5514c63. A seeded fuzz now lives intest/markdownStream.test.tsx.🤖 Generated with Claude Code