Skip to content

Studio: long chats stop re-rendering source badges per token and tool cards per run - #16277

Merged
danielhanchen merged 5 commits into
mainfrom
perf/r15-long-chat-render
Nov 1, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
perf/r15-long-chat-render

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Long chats did two pieces of avoidable render work while a reply streamed. Neither changes what is drawn.

What changes

  • Source badges re-rendered on every token. SourcesGroup read the whole message with useMessage() and rebuilt its source list each render. Every streamed token of a web search answer therefore re-rendered all of its source badges twice, once for the visible row and once for the hidden copy used to measure rows, each with a Radix HoverCard tree. On a streamed token that was about 190 of the roughly 200 components React rendered. SourcesGroup now selects the message's URL sources as a string key (memoized on the content array), parses it once per key, and passes the list to a memoized SourcesGroupView. The view is the old body, unchanged.
  • Every tool card in the history re-rendered when a run started or ended. useToolOutputFor subscribed to thread.isRunning for its stdout fallback, so every python and terminal card in the chat re-rendered twice per turn. At 1000 messages the end-of-stream commit rendered about 7,100 components. The hook now selects the fallback string itself. It returns the same value in every case, and for cards without a fallback entry it stays "".
  • Harness: smoke-thread-weight-main.tsx gets an opt-in agent.sources seed option and a &sources=1 stream option. The defaults are unchanged.
  • New browser check tests/studio/playwright_long_chat_renders.py, wired into the frontend workflow. It counts renders through a React DevTools hook while a 60-chunk reply with sources streams into a 30-message chat with tool cards and sources.

Results, base vs head

Setup: a production build of the real Thread with a seeded local runtime, headless Chromium at 1440x900 with 4x CPU throttle. Each assistant reply has reasoning, a tool call (web search with 6 sources, terminal or python), and markdown with a table and a code fence. A compaction marker appears every 25 replies. The streamed reply is 100 chunks behind a web search call with 6 sources. Each arm ran 3 times, interleaved base/head. Values are median [min-max].

base head
1000 messages: stream wall time 22534 [22026-25487] ms 17830 [16458-20393] ms
1000 messages: longest main-thread task while streaming 1163 [870-1575] ms 646 [588-687] ms
1000 messages: long-task total while streaming 19335 [18322-22148] ms 13738 [12277-17940] ms
1000 messages: largest React commit 301 [224-341] ms 90 [80-96] ms
1000 messages: React commit time, whole stream 1353 [1127-1468] ms 946 [667-986] ms
200 messages: largest React commit 75 [66-75] ms 36 [32-36] ms
200 messages: React commit time, whole stream 704 [643-768] ms 446 [375-466] ms
200 messages: component renders, whole stream (top 25 components) 20228 2904
200 messages: longest main-thread task while streaming 237 [212-267] ms 170 [137-187] ms
Render-count check: source badge / python+terminal card renders 366 / 20 0 / 0

Opening a chat did not change: first paint, full mount time, heap and DOM node count were all within the base spread. Stream wall time at 200 messages was also unchanged (4249 vs 4229 ms, overlapping ranges).

Identical output:

  • 14 screenshot pairs: 1440x900 with 200 messages and 520x900 with 60 messages. Each covers the bottom, three scroll positions, an open source hover card, after the stream, and the top after the stream.
  • In every pair, the thread's innerText, its ARIA snapshot and its outerHTML are identical. In outerHTML, assistant-ui's random message ids are renamed to their order of appearance.
  • Pixels: 39 px differ across the 14 head pairs, and 20 px differ when base is compared with itself. In both cases the differences sit in the composer fade and a 1 px column, with the same maximum channel delta.

Identical output while streaming, not only at the end: a stepped model advanced one chunk at a time, so both arms are captured at the same point. The stream covers text only, a python call with partial arguments reusing a history call id, a terminal call, the result arriving, fallback and own output changing mid-run, and sources appearing, renamed, reordered, duplicated with a different id, gaining a description and losing a title, up to 17 sources (the "+N more" collapse). It ends with the run finishing and the output store being cleared. It ran as a straight stream, cancel at step 2, switching threads and back mid-run, and hovering a badge mid-stream, each with tools expanded and with the default visibility: 126 frames per arm.

  • innerText is identical in all 126 frames. The fallback output appears and disappears in the same frames in both arms, and badge counts match at every step.
  • outerHTML is identical apart from one scroll timing attribute (--aui-scroll-stabilizer / data-aui-following), which varies by the same amount between two runs of the same arm.

Tests

  • npm test: 14524 tests, 14523 pass, 1 skipped, 0 fail, on base and on head.
  • npm run typecheck and npm run build pass on both. npm run bundle:check is within budget.
  • eslint and biome report the same findings on the touched files as on base.
  • python3 tests/studio/playwright_long_chat_renders.py fails on base (366 badge renders) and passes on head.

Not covered

  • The largest remaining per-token cost is inside assistant-ui. Every store update re-runs every message's client resource (ThreadClient maps all messages through tapClientLookup). At 1000 messages, unthrottled, that is about 11 to 15 ms per streamed token. This PR does not touch it.
  • Measured on the thread harness, not the full app shell with a live backend.
  • Reconnecting to a durable run and switching message branches mid-run have no harness; they rest on the selectors returning the same value for the same inputs.
  • Chromium only. Firefox, WebKit, and the Tauri WebKit and WebView2 builds were not run.

… cards per run

A streamed token rebuilt the reply's source list, so every source badge (and its hidden
measuring copy) re-rendered on each token of a web search answer. SourcesGroup now selects
the message's URL sources as a string and hands an unchanged list to a memoized view.

Every python / terminal card in the history subscribed to thread.isRunning for the stdout
fallback, so each run start and end re-rendered all of them. The hook now selects the
fallback string itself, which stays "" for cards without a fallback entry.

Rendered output is unchanged. Adds a browser check that counts renders while a reply with
sources streams into a chat with tool cards.
@danielhanchen danielhanchen self-assigned this Nov 1, 2026
# Conflicts:
#	.github/workflows/studio-frontend-ci.yml
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-01T10:47:23.660125Z
We couldn’t complete this review. Comment @codex review to try again.
01d877f Draft marked ready
ℹ️ 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

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: ac2df368f5

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# Conflicts:
#	.github/workflows/studio-frontend-ci.yml
@danielhanchen
danielhanchen marked this pull request as ready for review November 1, 2026 10:47
@danielhanchen
danielhanchen merged commit edde292 into main Nov 1, 2026
@danielhanchen
danielhanchen deleted the perf/r15-long-chat-render branch November 1, 2026 10:47
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.

1 participant