chat-ui: memoize timeline rows to stop full re-render per streamed token - #304
Merged
Conversation
…r token Every streamed inference.text.delta rebuilds the timeline's items array (mergeStreamingReply in chat-workspace.tsx), which re-rendered every MessageParts row in the conversation on every token — not just the growing bubble. Unchanged items keep the same object reference across that rebuild, so a memo guard that ignores handler props (recreated every render regardless, carry no displayed data) skips the re-render for every row whose data didn't actually change. CL-6625
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
CL-6625 (chat feels slow/jerky) found the top offender:
WorkbenchTimeline(packages/chat-ui/src/timeline.tsx) has noReact.memoanywhere, and theitemsarray it receives is rebuilt fresh on every render (mergeStreamingReply/mergePendingSends/appendReplyTimedOutNotice, chat-workspace.tsx:1276-1285). A real reply firesinference.text.deltamany times per second (see streaming-reply.ts's own docs), and each one re-renders everyMessagePartsrow in the whole conversation — not just the growing streaming bubble.Unchanged items keep their own object reference across that rebuild (the merge helpers spread
[...items, newItem]without touching existing elements), so a memo comparator that treats handler props as always-equal (they're recreated every render regardless and carry no displayed data, only callbacks) makes memoization actually effective: rows whose data hasn't changed skip re-render entirely during a live turn.This is the top-ranked fix from the CL-6625 findings comment — smallest safe change, no transport/streaming-architecture rework, and stays out of
failed-turn-strip/the composer retry path (CL-6624's territory).Test plan
tsc -p packages/chat-ui/tsconfig.json --noEmiteslint packages/chat-ui/src/timeline.tsxbun run testinpackages/chat-ui(665 pass)