Repository navigation
🫣 perf: Defer Offscreen Message Toolbars Until Needed - #18551
Merged
Merged
Conversation
Opening a long conversation built a toolbar for every message as its rows mounted: the copy, edit, branch, feedback, read-aloud and rerun buttons that show on hover or under the latest message. That was close to half of what opening a 246-row thread cost the main thread, and most of it in a thread four times as long. A row a long thread adds after its first commit now leaves its toolbar out until the thread's row observer finds it within a screen of the viewport, then keeps it. The footer holds the toolbar's height throughout. The rows a thread opens on, the latest message, short threads and rows outside the main thread view are unchanged. The copy-last-response and edit-last-message shortcuts reach their row first, and screenshot export mounts every toolbar before it clones. Adds e2e/benchmarks-fade/open.perf.spec.ts, which traces a reload, a switch from the sidebar and a switch while a reply is in flight.
This was referenced Nov 19, 2026
danny-avila
marked this pull request as ready for review
November 20, 2026 03:05
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 keeps the page busy for seconds after its first rows appear, in a run of tasks long enough to drop clicks and keystrokes, and the cost grows faster than the conversation does. Close to half of it, and most of it in a very long conversation, is building a toolbar for every message: the copy, edit, branch, feedback, read-aloud and rerun buttons that show on hover, or under the latest message.
A long thread already mounts in steps: the rows around the scroll position first, then the rest a chunk at a time, and rows more than a screen from the viewport are skipped by the browser. The toolbar was still built for every one of those rows as it mounted, although nobody can press a button in a row a thousand pixels off screen.
With this change, a row that a long thread adds after its first commit leaves its toolbar out until the row comes within a screen of the viewport, then keeps it. The footer holds the toolbar's height the whole time, so no row changes size. Nothing changes for the rows a thread opens on, for the latest message, for a thread short enough to mount at once, or for rows outside the main thread view.
Measured with the new
e2e/benchmarks-fade/open.perf.spec.tson the built client, CPU unthrottled, switching to the conversation from the sidebar and tracing until every row is in:devdevReloading the 246-row thread goes from 2,959 to 3,242 ms, with every row in at about 3.1 s, to 1,832 to 2,012 ms, with every row in at about 1.7 s; tasks over 50 ms go from 11 or 12 to between 4 and 6. Each figure is three rounds (two for the 984-row thread). The 984-row thread is the 246-row export chained four times.
devhere is this branch's build with the change switched off by a temporary flag that is not in the diff, so the two sides differ in nothing else.The other benchmarks in that directory, run on the same build with the change switched off and on:
devA send and its completion re-render the toolbar of every row that has one, which is why a run in a freshly opened thread gets cheaper too; a reader who has scrolled through the whole thread has mounted every toolbar and is back to the first column. The first pass up the 246-row thread costs about 9% more, the toolbars mounting as their rows come near; the longest task of that pass is 10 to 11 ms either way.
Not addressed here: switching to a thread while it has a reply in flight mounts every remaining row in one commit instead of in steps. That is a single task of 1.5 s in the 246-row thread and 7 s in the 984-row one, with or without this change, and it is the next change. Not measured: Firefox and Safari, a throttled CPU, a touch device.
How it works
A row learns once, as it mounts, whether a widening step added it. The provider keeps that in a ref the rows read rather than in a context value, because a value that flipped would re-render every row of the thread to tell the few that are mounting.
The thread's existing observer (the one that marks rows
data-offscreen) calls the row back the first time it finds it within a screen of the viewport. The toolbar then mounts in a transition, so a fast scroll through a long thread does not trade one blocked frame for another. Once mounted it stays.Three things reach a row's toolbar from somewhere else, and each mounts what it needs synchronously through
reachRoworrevealOffscreenRows:A browser without
IntersectionObserverholds nothing back.Type of change
Testing
The benchmarks above, on the mock e2e lane in a real browser. Two new scenarios in
e2e/specs/mock/scenarios/offscreen-rows.spec.tsopen an 80-turn thread and check that the rows far from the viewport have no toolbar while every row near it has one, and that a far reply gains its copy button as a scroll brings it near, at the same row height, shows it on hover, and keeps it after scrolling away.Tested environments/configuration:
Automated tests:
packages/chat: new cases inoffscreen.spec.tsx(a far row holds its toolbar back until the observer reports it near, then keeps it;reachRowandrevealOffscreenRowsmount it before returning; nothing is held back outside a watched thread or withoutIntersectionObserver),useProgressiveRowMount.spec.tsx(useWidenedRow) andMessageFooter.spec.tsx(the stand-in, the latest message). Four of them fail with the gate removed.npx jest src/react/messages src/components/messages,npx tsc --noEmit.client: a new case inuseKeyboardShortcuts.spec.tsx(copy-last-response reaches the last reply's row before pressing),npx jest src/components/Chat/Messages src/components/Messages src/Providers(108 suites),npx tsc --noEmit.offscreen-rows,long-conversation-mount, and the specs that press toolbar buttons (hover-actions,hover-buttons,message-actions,message-footer,mouse-reveal,fork-feedback,turn-regenerate,message-tree,message-edit-layout,branch-history,thread-rows,tts-cacheand others): 31 scenarios on this head, and 99 across the wider set on the commit before the last rebase.