Skip to content

⚡️ perf: bound concurrent stream fades and fold faded tail spans - #8

Merged
Innei merged 5 commits into
mainfrom
perf/streaming-tail
Nov 19, 2026
Merged

Innei merged 5 commits into
mainfrom
perf/streaming-tail

Conversation

@Innei

@Innei Innei commented Nov 19, 2026

Copy link
Copy Markdown
Member

Problem

Fast streams created one composited opacity animation per char or word. With bursty input this meant over a thousand concurrent layers. The cost landed on the compositor and GPU threads, not in JS. An 8K paragraph streamed in 256-char chunks used 1.6 s on the compositor thread, had a 233 ms frame p95, and left about 2,300 spans in the DOM after the stream ended. Word granularity also had a bug: after the first whitespace, every birth was NaN. Those words never collapsed into text, so each word stayed a span for good.

Changes

  • 🐛 Word births: whitespace segments now get births, so the birth chain no longer breaks into NaN.
  • ⚡️ One span per display frame: in-flight chars or words born in the same ~16 ms frame share one span. The number of concurrent fades now depends on frames in flight, not on stream throughput. A frame group collapses into text only once its whole frame has faded, so a group never splits and remounts.
  • ⚡️ Fold faded spans: StreamTail re-renders itself once after its last fade, so the final commit of a stream no longer leaves spans behind.
  • 🔧 pnpm bench: a Chromium replay benchmark against @pierre/words and streamdown (Vercel). It uses their fixtures plus generated long paragraphs and fences, and supports --throttle for CPU slowdown. It measures main-thread time from CDP, frame p95, heap and final DOM size.

Results

Main-thread ms, animated, median of 3 runs, Apple M4 Max, Chrome 157:

Scenario Fixture Words Vercel Before After
24 chars / 50 ms assistant-review 352 915 632 418
24 chars / 50 ms 8K paragraph 555 1323 982 566
256 chars / 40 ms assistant-review 63 175 460 112
256 chars / 40 ms 8K paragraph 57 184 470 (frame p95 233 ms) 86 (frame p95 16.7 ms)
256 chars / 40 ms, 4× throttle 8K paragraph 197 747 3156 (35 frames > 50 ms) 338 (0 frames)

After the stream ends, 2–110 DOM elements remain, down from up to 3,400.

What to check

  • Char mode at high speed: chars born within one frame now fade together.
  • Word mode: words now stagger within a commit. Before this change, all new words in a commit faded at once.
  • End of a stream: spans fold into text about 180 ms after their fade. Watch for flicker or a re-fade.
  • Downstream code: rehypeStreamAnimated output items can now hold several chars or words, and faded chars are no longer .stream-char spans.

Not changed

Smoothing pacing, block lexing and freezing, code fences, and the prefers-reduced-motion rule.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-19T19:21:47.251253Z
We couldn’t complete this review. Comment @codex review to try again.
46aa34b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@Innei
Innei merged commit e67f932 into main Nov 19, 2026
2 of 3 checks passed
lobe-tsukumo Bot pushed a commit that referenced this pull request Nov 19, 2026
## [1.4.6](v1.4.5...v1.4.6) (2026-11-19)

### ⚡ Performance Improvements

* Bound concurrent stream fades and fold faded tail spans, closes [#8](#8) ([e67f932](e67f932))
@lobe-tsukumo

lobe-tsukumo Bot commented Nov 19, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.4.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant