Repository navigation
🥞 perf: Progressively Mount Long Threads During Active Replies - #18555
Merged
Merged
Conversation
A long thread mounts in steps, but a run under way switched that off: the first sixteen rows appeared, then every remaining row mounted in one synchronous commit. Returning to a conversation whose agent was still working froze the page for as long as the whole thread takes to render: 1.5 s for 246 rows, 7 s for 984. A thread anchored at its end, the default, now keeps widening while a reply is in flight: four rows a frame, each step committed at once, because a reply's frames would discard a transition's unfinished render. A thread anchored at its start does not hold the reply's row and still mounts the rest at once. A step also no longer renders a component per message. Rows wait on the window through a subscription instead of reading it from context, so only the rows a step adds render, whatever the thread's length.
…t Scenario The scenario streamed a reply that could finish before a slow machine had reloaded, and its second half moved the reader with a synthetic scroll that raced the landing every open performs. It now starts a run that stays in flight, checks the steps and the resting place, and stops the run. The reader-place half is dropped: it failed on timing that has nothing to do with the steps.
danny-avila
force-pushed
the
danny-avila/mount-steps-while-replying
branch
from
November 20, 2026 03:07
5cd97e7 to
049c856
Compare
danny-avila
marked this pull request as ready for review
November 20, 2026 03:07
This was referenced Nov 20, 2026
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
Opening a long conversation that has a reply in flight freezes the page. A long thread normally mounts in steps, the rows around the scroll position first and the rest a chunk at a time, but a run under way switched that off: the first sixteen rows appear, then every remaining row mounts in one synchronous commit. In a 246-row thread that commit is a single task of 1.5 s; in a 984-row thread, 7 s, during which nothing on the page responds. It happens on every return to a conversation whose agent is still working, on a reload of one, and when a message is sent while a long thread is still mounting.
With this change the thread keeps mounting in steps while a reply is in flight. The reply's row is at the thread's end, which the window of mounted rows always holds when it is anchored there (the default), so the rows above keep arriving: four per frame, each step committed at once. The longest task of the open drops to the first commit's, about 100 ms, whatever the thread's length. A thread anchored at its start (auto-scroll switched off) does not hold the reply's row and still mounts the rest at once when a run starts, as before.
A step also stops costing a render of every message in the thread. Each level of the thread read the window from context, so widening it re-rendered a component per message on every step: work that grows with the thread, paid once per step. Rows now wait on the window through a subscription and only the rows a step adds render. That is what makes small steps affordable, and it shortens the ordinary open as well.
Measured with
e2e/benchmarks-fade/open.perf.spec.tson the built client, CPU unthrottled, switching to the conversation from the sidebar. "In flight" is a run that has started and not produced a token yet; "streaming" is one writing its reply as the thread mounts.The 984-row thread with a reply streaming keeps the main thread about 88% busy for nine seconds while it mounts, in frames of about 23 ms: responsive, not idle. The total is what mounting a thread that size costs; this change is about no part of it being a freeze. Not measured: Firefox and Safari, a throttled CPU.
Stacked on #18551: the rows these steps add count as mounted away from the reader, so they leave their toolbars out until scrolled near.
How it works
Why the steps beside a reply are not transitions: every frame of a streaming reply is an urgent update, and an urgent update discards a transition's unfinished render. A 32-row chunk takes longer to render than the gap between two frames, so it would be started over again and again without landing. Beside a reply each step is four rows, committed in one go, which fits in a frame next to the reply's own update.
function MultiMessage(...) { - const mountWindow = useRowMountWindow(); // context: every level renders on every step + const rowMounted = useRowMounted(messagesTree?.[0]?.depth ?? 0);The window still lives in the hook's state, and the provider still publishes it after each commit, so a provider driven by its prop alone (no gates passed) mounts rows one commit later rather than not at all. The scroll anchor is unchanged: the first mounted row's document offset is captured before a step and the scroll position corrected by its measured shift after it, which keeps a reader's place whether they are riding the reply or have scrolled up.
Type of change
Testing
The benchmarks above, on the mock e2e lane in a real browser. A new scenario in
e2e/specs/mock/scenarios/long-conversation-mount.spec.tsseeds a 160-turn conversation, starts a run that stays in flight, and reloads: the thread mounts in steps (no frame adds more than a chunk of rows), rests on its end, and has every row in while the run is still under way. With the old rule restored on the same build, an earlier form of the scenario failed with a single step of 145 rows.A reader who scrolls up while the rest of the thread is still arriving is held by the same scroll anchor as before, and it holds no better than before: in the 984-row thread a wheel-up during the mount leaves the marked row 1,527 px from where it was, with no reply in flight, on
devand on this branch alike. That is rows above the reader changing height after their step, which the anchor does not see; it is not addressed here. A scenario for it was dropped: it raced the landing at the thread's end that every open performs.Tested environments/configuration:
Automated tests:
packages/chat,useProgressiveRowMount.spec.tsx: a thread anchored at its end keeps its window while a run is under way and widens four rows a frame without a transition; a run starting part way through does not complete the mount, and the steps grow again once it ends; a thread anchored at its start still mounts the rest at once. For the gates: a step renders the rows it adds and no other row; a row whose level only now has a depth inside the window (a turn arriving at the thread's end) is in its first commit; a provider given no gates follows its prop a commit later.npx jest src/react/messages src/components/messages,npx tsc --noEmit.long-conversation-mount,offscreen-rows,streaming,conversation-management,reload-resume,resume-body-end,pane-resume,stream-disconnect,stream-events,message-tree,branch-history,thread-renderers,thread-rows,thread-fold,scroll-control-fade,thread-end-width,rail-nav-statesand others: 74 scenarios, then 46 of them again, then the long-conversation spec five times over on the final head.