perf(web): coalesce streaming Markdown renders - #4349
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a46d860c61e47a8f6ad2ff9b7334ae213d5ae908. Configure here.
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — The PR changes an existing assistant-message path by automatically suppressing Markdown parsing and DOM updates between 50 ms snapshots during streaming. Since this gate controls when substantial rendering work occurs without an operator choice, the runtime behavior merits human review. You can add or adjust custom eligibility rules. Learn more. |
6d2b488 to
26ebe2f
Compare
|
Final refresh on current main: 325e1fe9a.
|
|
@juliusmarminge @mudit-loya — this is ready for human review and Linux reproduction validation on The current-main version coalesces streaming Markdown parsing to at most once every 50ms, while synchronously flushing the complete final response. It preserves current links, task lists, raw HTML, tables, and code-block behavior. The focused suite is 54/54, web typecheck and isolated browser streaming verification pass, and all CI/Bugbot/Macroscope checks are green (including Approvability and UI Consistency). For review, the main tradeoff is the 50ms intermediate-render cadence; final rendered output and stream-completion timing remain unchanged. A quick check against the original Linux high-CPU reproduction would be especially useful. |
|
@nateEc how can we test this fix? |
|
Thanks for offering to verify this. The useful comparison is the same one from #4074, using the same model and a response of roughly the same length:
The primary success signal is that long-thread streaming no longer scales sharply above the fresh-thread result (the original report was roughly 76%/65% versus 35%). The fresh-thread baseline may still be non-trivial; this PR specifically targets the per-token full reparse. Please include the T3 commit, Linux/desktop version, and the four peak samples when reporting back. |
26ebe2f to
325e1fe
Compare
|
@juliusmarminge Ready for another review on 325e1fe9a. Rebased onto current main; implementation range-diff is unchanged, 65/65 focused Markdown tests pass, and all 20 GitHub checks completed with 0 failures. Linux CPU/rendering repro instructions were sent to @mudit-loya. Mergeable state is clean. |
325e1fe to
6497047
Compare
Dismissing prior approval to re-evaluate 6497047
|
@juliusmarminge Rebased onto the latest main; the focused ChatMarkdown suite passes and the current CI is green. Could you take a human review when you have a moment? |
6497047 to
ac980ca
Compare
|
Rebased onto current main in ac980ca. The resolution retains the current link-target handling and applies the streaming Markdown render coalescing unchanged. Verified: |
|
CI note: the only failing |
- 将高频 token 更新限制为每 50 毫秒最多触发一次 Markdown 解析。 - 流式结束时同步刷新完整文本,保留链接、任务列表与代码块行为。 - 最新主线上的 65 个定向测试通过,补丁经 range-diff 确认未漂移。 - Web 类型检查仅剩主线 electronPasskeys 测试中的两条既有错误。
ac980ca to
a73ad50
Compare
|
Follow-up: #9558 is now in main, and this PR has been rebased onto that repaired CI baseline. Its targeted tests were rerun successfully; the updated commit is now awaiting the fresh CI result. |

Closes #4074
Summary
Verification
vp test run apps/web/src/components/ChatMarkdown.logic.test.ts apps/web/src/components/markdown-list-indentation.test.tsx apps/web/src/components/markdown-links.test.ts(27 passed)vp run --filter @t3tools/web typechecktest-t3-app: streamed a live Codex response containing paragraphs, bullet/task lists, a table, and a fenced TypeScript block; all rendered after completionNote
Low Risk
UI performance tuning in chat markdown rendering only; behavior change is limited to update cadence during streaming, with immediate flush when streaming stops.
Overview
Streaming assistant messages no longer trigger a full
react-markdownparse on every token. WhileisStreamingis true,useStreamingMarkdownTextapplies the latest text on a 50ms cadence viastreamingMarkdownRenderDelay, canceling superseded timers so rapid deltas coalesce.ChatMarkdownnow drives link metadata, inline-code file links, task-list marker offsets, and the memoizedReactMarkdowntree from that throttledrenderedText. When streaming ends, the hook syncs immediately to the finaltext(no artificial delay on the completed message).A small
ChatMarkdown.logichelper plus unit tests cover interval math, including backward clock jumps.Reviewed by Cursor Bugbot for commit a73ad50. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Coalesce streaming Markdown renders in
ChatMarkdownto a 50ms intervaluseStreamingMarkdownTexthook in ChatMarkdown.tsx that throttles text updates during streaming to at most one render per 50ms, clearing superseded timers and recording render timestampsstreamingMarkdownRenderDelayutil in ChatMarkdown.logic.ts that computes the non-negative remaining delay since the last render, clamping elapsed time to zero when the clock moves backwardsChatMarkdownnow uses throttledrenderedTextfor file-link extraction, inline-code extraction, task-list markers, and the memoizedReactMarkdownoutput; non-streaming renders sync immediatelyChatMarkdownno longer re-parses and re-renders on every incoming text value; output updates at most every 50ms while streaming is activeMacroscope summarized a73ad50.