Skip to content

task: smoother streaming with media#370

Open
chloebyun-wd wants to merge 4 commits intomainfrom
task/smoother-streaming-with-media
Open

task: smoother streaming with media#370
chloebyun-wd wants to merge 4 commits intomainfrom
task/smoother-streaming-with-media

Conversation

@chloebyun-wd
Copy link
Copy Markdown
Contributor

@chloebyun-wd chloebyun-wd commented Apr 13, 2026

Add support for smoother media streaming:

  • keeps chat pinned to latest content more reliably during stream
  • handles post-render/media-size changes better for scrolling
  • reduces jank during streaming updates
  • avoids local storage pollution from incomplete/interrupted stream messages

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.

Metric main branch this branch Change
Frames pinned to bottom (<5px) 59.6% 84.0% +41%
Avg scroll jump size 84px 50px −40%
Max jump (worst hitch) 228px 128px −44%
Jumps >150px (visible snaps) 6 0 eliminated
Max distance behind bottom 228px 128px −44%
Scroll updates per stream 34 65 2× more frequent

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.

Metric main smoother Change
localStorage writes 265 5 −98%
Total localStorage time 7.50ms 0.20ms −97%
Total elapsed (stream) 9,263ms 28,697ms

Note: the longer elapsed time on the smoother run reflects a longer response being streamed in that session, not a regression. The write-rate reduction (writes per second of streaming) is roughly 50× lower on the branch.

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.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/components/bubbles/BotBubble.tsx Outdated
Comment thread src/components/bubbles/BotBubble.tsx Outdated
Comment thread src/components/bubbles/BotBubble.tsx Outdated
Comment thread src/components/Bot.tsx Outdated
Comment thread src/components/Bot.tsx Outdated
@chloebyun-wd chloebyun-wd force-pushed the task/smoother-streaming-with-media branch from fe0ff97 to fe3240e Compare April 17, 2026 17:21
@chloebyun-wd chloebyun-wd marked this pull request as ready for review April 17, 2026 19:30
@HenryHengZJ
Copy link
Copy Markdown
Contributor

is there a jira ticket where i can look at the recordings + screenshots? before/after

 # links and colors are correct during streaming, not just at stream end
@chloebyun-wd chloebyun-wd force-pushed the task/smoother-streaming-with-media branch from fe3240e to 59a9140 Compare April 24, 2026 18:56
@chloebyun-wd
Copy link
Copy Markdown
Contributor Author

Its hard to capture the changes with screen recordings so ive added some metrics Ive captured between the two branches

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants