task: smoother streaming with media#370
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the chat scrolling and message streaming logic to improve the user experience and optimize message persistence. Key changes include the introduction of an isStreaming flag to defer message updates, a scrollToBottom helper, and an onMessageRendered callback to handle dynamic content like images. Review feedback highlights a bug where auto-scrolling is blocked during streaming, performance concerns regarding manual DOM manipulation and internal component definitions, and the need to refine message cleanup logic to prevent the loss of partial metadata (tools, artifacts) during stream interruptions.
fe0ff97 to
fe3240e
Compare
|
is there a jira ticket where i can look at the recordings + screenshots? before/after |
fe3240e to
59a9140
Compare
|
Its hard to capture the changes with screen recordings so ive added some metrics Ive captured between the two branches |
Add support for smoother media streaming:
This branch makes two improvements to the streaming message experience: auto-scroll stays pinned to the bottom more reliably, and localStorage writes during streamings are significantly reduced.
Auto-scroll behavior
Measured on a ~14s streamed response with ~3,000px of content growth. Frame rate is identical between branches (~60 FPS, zero long tasks on either), so this is purely a scroll-behavior improvement — the view stays closer to the latest content, more often, with smaller corrections.
Perceptual impact: the view stays glued to the latest streaming content 84% of the time instead of 60%, and the large "snap to bottom" hiccups on main are gone.
How it works: rendering isn't faster — frame times are identical. The branch updates scroll position more often in smaller steps, trading jump magnitude for frequency.
localStorage writes
Measured over a single streamed response. Per-write duration is unchanged (~28μs per write on both branches), but the branch writes dramatically less often.
Why this matters: each localStorage write is synchronous and blocks the main thread. Writing on every streamed chunk contends with the same main-thread budget that auto-scroll, paint, and input handling need. Reducing writes from hundreds to single digits per response frees that budget.
Combined impact
The two changes reinforce each other. Fewer main-thread stalls from localStorage writes make it easier for the scroll scheduler to update on time, and the scroll scheduler itself corrects more frequently with smaller increments. Together they produce the "smoother streaming" effect this branch is named for.