Repository navigation
Studio: paint a long thread's newest messages immediately instead of rebuilding all of them first - #9058
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ecb065c5df
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const shift = | ||
| captured.element.getBoundingClientRect().top + | ||
| viewport.scrollTop - | ||
| captured.documentOffset; | ||
| // The hook decides whether this is acted on; see adjustForContentInsertedAbove. Rounding | ||
| // down to whole pixels keeps a subpixel reflow from issuing a scroll write every frame. | ||
| if (Math.abs(shift) >= 1) adjustForContentInsertedAbove(shift); |
There was a problem hiding this comment.
Disable native anchoring before applying the manual correction
When a user detaches by scrolling upward before progressive mounting converges, Chromium's default scroll anchoring can already increase scrollTop to compensate for the prepended rows. The viewport does not set overflow-anchor: none, so this additional correction applies the inserted height a second time, moving the reader away from the content they were viewing and potentially clamping/re-attaching them near the bottom. Disable native anchoring on this viewport or calculate only the remaining uncompensated movement.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Rejecting the claim, though the second half of the sentence is what the code already did. The correction is not the inserted height, it is the residual: the anchor is captured in viewport space, so a viewport the browser has already compensated reports zero and nothing is applied. Applying the full insertion on top of native anchoring was the earlier version of this code and it did exactly what you describe, walking scrollTop 22,897 to 117,104 and dumping the reader at the bottom; that is why it measures a residual now. Measured on the current code at 150K characters with a reader parked 4000 px above the bottom: per-widening corrections of -3 to -5 px and 8 px of total on-screen drift across the whole build-in, on Chromium 151, WebKit 26.5 and Firefox 153.
The real defect in this area is the one in the sibling item about gesture frames, which is where the residual assumption breaks: on an engine that does not anchor, the residual is the whole insertion. That is fixed in 5a2ba76, by feature-probing whether the engine compensates rather than by disabling native anchoring, so the compensating engines keep the behaviour that is measured above.
… through The correction was measured in document space, following LibreChat#14901. In our viewport that double-corrects: Chromium's own scroll anchoring has usually already moved scrollTop by the inserted height, and adding the full insertion on top of it walked a detached reader 22,897 -> 117,104 and dumped them at the bottom of the thread. Viewport space measures the residual instead, which is single-digit pixels. That exposed the other half: across the transition-deferred gap the reader's own wheel is indistinguishable from a layout shift in viewport space, so a 4000px scroll during a widening was cancelled inside the frame. The hook now counts user gestures and the correction skips any frame one landed in. Found by tests/studio/probe_progressive_anchor.py, added here.
…the scroll correction Four fixes, each with a measurement behind it. 1. The cold open never armed. ProgressiveMessages mounts before the history adapter has delivered anything, so the useState initialiser ran at count 0, declined, and the whole thread then landed in one unbounded commit. Measured in the app: mount at count 0, count 220 about 160ms later, same resetKey, first paint carrying all 220 rows. The window now re-arms on the commit that first fills an empty tree. Gated on the previous count being zero rather than on crossing MIN_PROGRESSIVE_MESSAGES, so it cannot window a conversation the reader is already in the middle of. 300K, chromium, medians of 5: cold open 2498.8ms/220 rows to 270.6ms/16 rows, against a base of 2536ms. 2. The scroll correction assumed the engine had already done the work. It measured the anchor in viewport space, which reports the residual left by CSS scroll anchoring, and dropped any frame the reader gestured through on the grounds that the residual is single-digit pixels. Both hold only where the engine anchors. WebKit implemented scroll anchoring in February 2026, so every shipping Safari and every iOS browser today does not, and Playwright's WebKit 26.5 does, which is why this was invisible. Measured at 150K with overflow-anchor:none forced on the viewport: one dropped frame walked a parked reader 19,259px, and dropping every frame walked them 45,873px, on all three engines. The correction is now a tested pure function that picks its space from a one-off feature probe: viewport-space residual where the engine compensates, document space where it does not, and no frame is dropped in the second case. Same fixture with the fix: 12px and 13px. 3. A thread that shrank under a live window painted nothing. The row loop clamped start to count, which makes it emit zero rows. Measured: dropping a 220-message thread to 10 while the window sat at start 204 painted an empty column for 2 to 8 frames on all three engines. The window is dropped in that commit instead. 4. completeProgressiveMounts sampled the completer set once, and the completers register from an effect, so a caller in the same task as the open returned on an empty set with 16 of 220 rows in the document. It now re-reads the set across frames, registers from a layout effect, and resolves on the commit that actually dropped the window rather than on a two-frame timer started at the call. Also resets adjustImplRef in the autoscroll teardown alongside the other two impl refs. Tests: the correction is now testable arithmetic, with both branches covered. The glue assertions read comment-stripped source for their positive matches too, so commenting the feature out no longer leaves them green, and every source slice requires both of its markers instead of silently widening to the end of the file. npm test 3514 passed, typecheck, build and biome clean.
…rrection is zero Two more paths where the scroll correction reads the wrong thing, both raised in review and both reproduced here. A scrollbar drag, PageUp, the arrow keys and middle-click autoscroll reach the autoscroll hook as nothing but a scroll event. They detach the reader through onScroll's 2px accumulator, but they never bumped the user-gesture counter, which only onWheel and onTouchMove touched. A correction measured across one of them therefore read the reader's own movement as a layout shift and reversed it. onScroll now counts any scroll with a non-zero delta. The two scrolls that are not gestures stay excluded by arithmetic rather than by a flag: the corrective write advances lastScrollTop with itself, and a native scroll-anchoring adjustment is advanced past by the resync below, so both arrive with delta 0. And a widening that native scroll anchoring absorbed in full needs no scroll write, but the browser still moved scrollTop by the whole inserted height and still fires a scroll event for it. Measured on a 400px scroller with 2000px inserted above the scroll position: one scroll event carrying the new offset, on Chromium 151, WebKit 26.5 and Firefox 153. The old early return left lastScrollTop a whole insertion behind, so that event arrived as a large downward scroll nobody made, and a reader who had deliberately detached within the 24px re-attach threshold, which detachFromBottom puts them at whenever the composer grows, was silently re-attached and yanked to the bottom on the next widening. The mount window now reports every widening including the zero ones, and the hook resyncs its bookkeeping whether or not it wrote. npm test 3516 passed, typecheck and build clean.
completeProgressiveMounts re-read the set across frames but still returned at the first empty reading, so the one case it was rewritten for stayed broken: a caller in the same task as a cold open finds the set empty because the history load has not finished, and two animation frames is nowhere near the roughly 160ms that load takes. The remaining passes never ran, because the loop exited on the first pass. An empty set is now only believed after 400ms of looking, while a set that has been non-empty and has since drained is believed immediately. A caller on a settled thread therefore pays 400ms, which is the right direction to be wrong in: the alternative is a screenshot or an export of a conversation that is not there yet, and anything reading the whole thread out of the DOM is already doing something far more expensive. npm test 3516 passed, typecheck and build clean.
…edict it
The correction measured the residual left by CSS scroll anchoring and dropped any frame the
reader had scrolled through, on the grounds that the residual is single-digit pixels. That
is true exactly while the browser compensates, and this code was not in charge of whether
it did. Two ways it does not, both measured at 150K characters on the 9016 fixture:
- No shipping Safari and no iOS browser has scroll anchoring at all today. WebKit
implemented it in February 2026 and Playwright's WebKit 26.5 has it, which is why this
was invisible here. Standing in for those builds with overflow-anchor:none, one dropped
frame walked a parked reader 19,259px and dropping every frame walked them 45,873px, on
all three engines.
- Anchoring is also suppressed per frame on engines that do have it, including after a
programmatic scroll, which is what a scrollbar drag, PageUp, the arrow keys and
middle-click autoscroll all become. On Chromium 151 with anchoring available and a reader
scrolling that way through the build-in: 45,161px of drift, because those frames were
both uncompensated and skipped. Counting those scrolls as gestures, which is what the
previous commit did, made this worse rather than better: it added skips to frames that
needed the correction most.
No measurement taken inside the frame can tell a compensated frame from a suppressed one,
so the browser is taken out of the loop rather than modelled. The viewport sets
overflow-anchor:none for as long as the mount window is open and gets it back the moment
the window closes, so a settled thread is exactly the thread that shipped before. With
nothing else moving scrollTop, the correction is document space, which subtracts the
reader's own movement arithmetically instead of dodging it, so no frame is ever skipped.
That removes the feature probe, the gesture counter and the whole notion of a skipped
frame. This is the shape LibreChat#14901 uses.
Measured on the same fixture and reader, native anchoring available, all three engines:
parked reader 12px drift (chromium), 6 to 13px (webkit)
scrollbar or keyboard 4,081 to 4,226px (chromium), all of it the reader's own scrolling
against 45,161px before
continuous wheel 4,612 to 4,852px (chromium), 4,489 to 4,819px (webkit), likewise
their own scrolling
npm test 3514 passed, typecheck, build and biome clean.
…hen the thread goes away Three more from review. getBoundingClientRect().top is measured against the window, so it also moves when the scroll container moves, and this container moves for reasons that have nothing to do with the thread: the composer grows a line, the mobile browser chrome slides away, a parent relayouts, the window is resized. Any of those landing between the capture and the widening commit read as content inserted above and were corrected away, moving a detached reader for no reason. Both ends now go through one sampleAnchor that subtracts the container's own top. completeProgressiveMounts awaits a promise this component resolves from an effect. If a thread switch or a navigation unmounted the component first, the layout effect's cleanup removed the completer from the set but left that promise pending forever, so a DOM capture that raced an unmount hung rather than completing. Outstanding waiters are now flushed on unmount, and the ref is emptied by the flush rather than by the effect that schedules it, so a cancelled frame leaves them to be settled rather than dropping them. probe_progressive_anchor.py cannot run on this branch, because it drives 9016's fixture and 9016 is not merged. It now exits with a message naming the three files it needs instead of a bare ModuleNotFoundError. Not fixed by vendoring a copy of the harness: two copies of a measurement harness is how the two copies stop agreeing, and this probe's numbers are only comparable to 9016's while there is exactly one of it. npm test 3515 passed, typecheck, build and biome clean.
One conflict, in thread.tsx, where #9042 replaced the message list's `components` map with a propless render prop so that assistant-ui's bail-out can skip a message subtree. This branch had replaced the same element with ProgressiveMessages. Resolved by taking both: ProgressiveMessages now takes `renderMessage={renderThreadMessage}` and maps MessageByIndexProvider over its bounded index range, rendering that one shared propless element in every row. That keeps #9042's optimisation exactly, because the bail-out it relies on is React's own element-identity check, and it is if anything a better fit here: a widening commit changes the row count every frame, which is precisely when handing React an identical element for the rows that already existed pays. ThreadPrimitive.MessageByIndex is not used, because its props carry the `components` object #9042 removed. MessageByIndexProvider is the same provider ThreadPrimitive.Messages mounts; what is dropped is RenderChildrenWithAccessor, whose accessor the thread's slot ignores and which emits no DOM. tests/thread-delete-render-budget.test.ts pinned the old JSX by spelling. It now pins the property instead: the slot reaches the row map, and neither list takes a components object. npm test 3623 passed, typecheck, build and biome clean.
The layout effect that set overflow-anchor:none on the viewport did not run in time, and the window it left open was the worst possible one: the first one. This component is a descendant of the viewport element, so on the commit that mounts them both, React runs this subtree's layout effects before the viewport's own ref callback. viewportRef.current is still null, the style is silently skipped, and it only lands on the next commit, which is the first widening. Measured on that version: computed overflow-anchor stayed auto from the first painted row at +305ms until the first widening at +803ms, so that widening ran with anchoring live and the document-space correction was applied on top of the browser's own. A reader who scrolled 4000px inside that window was left 776px short of where they parked, and one whose whole gesture landed inside it was carried back to 24px from the bottom of a 118,004px thread. Neither happened on the merge base. The style is now set in the same requestAnimationFrame that captures the anchor, immediately before the sample it would otherwise invalidate. That frame runs after a paint, so the ref is populated by definition, and it is by construction before any widening rather than merely soon. The layout effect keeps only the restore, and an unmount cleanup restores it too. Measured after, 300K, chromium, three repetitions, the reader's whole 4000px gesture landing inside the first mount window while 110,625px of content is inserted above them: parked at 4000px from the bottom, ends at 4028px, worst single frame 4px. The merge base under the same gesture never widens at all and holds 4000px. npm test 3623 passed, typecheck, build and biome clean.
…etween widenings Two findings from review, one of which turned out to be the other's cause. Disabling native scroll anchoring for the whole mount window means nothing absorbs a relayout above the fold that is not a widening: Streamdown replacing a pre when Shiki finishes highlighting it, KaTeX resizing a formula, an image landing. The autoscroll hook does not cover it either, because its mutation path pins a following reader and deliberately leaves a detached one alone. Measured by injecting a 600px height change into one row above a detached reader while the window was open: the reader moved the full 600px, against 0px on the merge base where native anchoring absorbed it. The correction now also runs between widenings, one frame later than the movement, which is invisible for a single reflow and is what keeps it to one getBoundingClientRect and one scrollTop read per frame. The first attempt at that measured nothing, and the reason is the second finding. The anchor was the first row in the list rather than the first row the reader can SEE. Widening prepends above everything, so for a widening any row will do; a relayout does not, because a row growing between the topmost row and the fold moves the reader while leaving the topmost row exactly where it was. Both paths now hold the first visible row, and that improved the widening correction too: the whole-gesture-inside-the-first-window case, three repetitions at 300K with 110,625px inserted above a reader parked 4000px from the bottom, goes from 28px of drift and a 4px worst frame to 0px and 0px. tests/studio/probe_progressive_reflow.py is the probe that found it, included with its own guards, since both of the things it initially got wrong produced a confident clean zero. npm test 3625 passed, typecheck, build and biome clean.
…chunk boundary A window whose start is at or past the end of the thread already causes every row to be rendered, because the row map falls back to no restriction. The STATE was left saying start 204 though, so the next widen clamped to count and subtracted a chunk: against a thread that had shrunk to 100 messages that is start 68, and rows 0 to 67, which the previous commit had just mounted, are unmounted again. Nothing in this design is allowed to unmount a row, and this was the one path that did. Fixed at both levels, because they protect different things. widen now returns null for any window at or past the end, which is a property the state machine can hold on its own and is covered by a test that asserts monotonicity for every reachable window and count rather than for one example. And the glue reconciles the stale state during render instead of leaving it for the next frame, so the committed state matches the tree that was committed with it. npm test 3627 passed, typecheck, build and biome clean.
|
| step | duration |
|---|---|
sudo apt-get update and the system deps |
1122.8s |
npm ci |
53.8s |
cargo test --no-fail-fast |
39.3s |
tauri build --debug --no-bundle |
51.5s |
| the 10 launch smoke | 203.5s |
So the actual work took about 6 minutes, which is what this job costs on main: the last five studio-tauri-smoke.yml runs there took 449, 406, 401, 427 and 422 seconds and all passed. The 18.7 minutes in front of it is the Azure apt mirror, the same thing that timed out Chat UI Tests (chat) on the previous head while it crawled a 13.6 MB package at roughly 50 KB/s.
Nothing in this branch is compiled into that step, so there is no mechanism by which it could be responsible. Re-running.
|
Closing the open question in the description: whether this branch's full-convergence cost survives #8992 being present. It does. And the caveat itself is now stale, which is the first thing to correct. #8992 is no longer in neither arm#8992 merged to main today at 13:19 UTC as squash commit So the run the description asks for needs no synthetic merge, and no conflict resolution could have distorted it. Control is Result: the cost is still thereHarness
Firefox overlaps on exactly one of the twelve pairs, control 2373 against treatment 2290, 83 ms. By the same min-max rule I have been applying to my own numbers all along, that is not resolvable, so do not quote the firefox +12.0% as a result. A rank test puts it at U=139/144, p=0.0001, which I report alongside the overlap rather than instead of it. One correction to the description. It says chromium is the soft arm and firefox the clean one. With #8992 present that is reversed: chromium is now the disjoint arm and firefox the overlapping one. The magnitude is unchanged, still the +10 to +17% band, so #8992 neither absorbs this cost nor amplifies it. The discrimination checkBefore trusting any of the above, the setup has to be able to see the effect it is looking for. Time to first real content painted, same runs:
Both disjoint. Rows in the DOM at first paint: 220 on the control in all 24 runs, 16 on this branch in all 24. The harness's own Both worktrees stayed clean across all 48 runs and the checksums of every changed source file and of the harness were taken before and after each probe and never moved. The harness file is the same git blob in both arms. What this does not settle
The trade in the description stands unchanged: an 8 to 10x improvement in time to first paint and the removal of a multi-second unpaintable frame, against a last row that lands 10 to 17% later. |
The initial tail was chosen by counting messages, but a message whose role the thread supplies no component for paints nothing: threadMessageKind returns "none" and ThreadMessage renders null, so the row has no height. Both importers preserve the system role (chat-import.ts, openwebui-import.ts), so an imported conversation whose last 16 messages are system entries opened on sixteen zero-height rows and no conversation at all until a later widening frame rescued it, which is the stall this window exists to remove rather than cause. Size the tail by walking back until it holds a full tail of renderable rows. Renderability comes from threadMessageKind through the new rendersAsRow, so there is no second list of roles to drift from the renderer. Reaching further back only ever mounts more, so the window still only widens. A thread with fewer renderable rows than one tail is not windowed at all. The predicate is read imperatively off the store, not through useAuiState: a selector touching the messages array runs on every store write, which would walk the thread once per keystroke and once per streamed token.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5c6e6d50e2
ℹ️ 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".
| // A pending widening capture owns the correction until its layout effect runs; stepping in | ||
| // between would correct the same movement twice. | ||
| if (!viewport || anchorRef.current) return; |
There was a problem hiding this comment.
Preserve the idle baseline before yielding to widening
When above-fold content changes after the previous widening commit but before the next captureAnchor callback—for example, a detached reader collapses a reasoning block or an async Shiki update commits between frames—this return prevents the idle sampler from comparing its pre-change baseline, while the widening capture records only the already-shifted layout. The subsequent widening correction therefore sees only the newly prepended rows and permanently leaves the earlier displacement. Unlike the previously reported visibility branch, the fresh evidence here is the pre-capture ordering gap: anchorRef.current is populated before this callback on every widening frame, so the only baseline predating that task is discarded rather than measured.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Refuted in a browser, on the mechanism this item names.
The specific claim was that the widening capture records only the already-shifted layout, so the correction sees just the newly prepended rows. Injecting 1200px above the fold in the disputed gap, against the same anchor element still connected, the capture's baseline comes back identical to the control to the pixel (vo -1029, st 29839), while the layout effect's now sample is exactly +1200. anchorCorrection returns 11526 to 12726, which is the prepend plus the reflow. At 600px it returns 11526 to 12126. The correction carries the reflow.
Net result over ten repetitions at 600 and 1200px: indistinguishable from the zero-injection control, -44 every time, where the -44 is the scene's own baseline. The displacement lasts about two frames and is then fully removed by the next widening commit. Six 600px injections do not accumulate.
The premise is correct and worth recording: idleRan is 0 in every repetition, with 28 to 40 skipped ticks, so the idle sampler genuinely never runs while the window is open. The widening layout effect absorbs the reflow instead, which is why the early return is not a lost baseline.
One neighbouring case does leave a residual, reported because it is real rather than because it changes this verdict: injection in a later task within the same gap leaves roughly 130 to 200px of 1200px. It is bounded, non-accumulating (six 600px injections totalling 3600px left 80 to 165px), and lands at message 220 of 220, after the final widening commit, where no later captureAnchor exists and overflow-anchor has already gone back to the browser. Different and much narrower window than this item describes.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f3f12d776e
ℹ️ 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".
| * | ||
| * Probe: tests/studio/probe_compact_tail_gap.py. | ||
| */ | ||
| export const INITIAL_MESSAGES = 16; |
There was a problem hiding this comment.
Increase the tail for consecutive compact assistant imports
For imported CSV/Open WebUI histories whose tail contains consecutive compact assistant messages, 16 rows cover only about 1280px using this file's measured 80px assistant-row height, rather than the documented 1643px alternating-role total. Thus an otherwise supported 1800px viewport can still paint a substantial empty band until the next expensive widening frame. The fresh case not covered by the prior alternating-tail measurement is the importers' arbitrary role ordering; size the initial tail for the shortest valid single-role sequence or adapt it after measuring the viewport.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one.
The compact-tail case is already measured rather than assumed. INITIAL_MESSAGES is documented from a 144-message thread whose last 24 messages are one-word replies, three rounds a point, across Chromium, Firefox and WebKit, at 900, 1080, 1440, 1800, 1840 and 1860px of clientHeight. At every one of those the empty band on the first painted commit is exactly the band a settled thread has, so none of it belongs to this window. The probe is tests/studio/probe_compact_tail_gap.py.
The undershoot above 1890px is known, quantified and deliberately left: 10px of band at 1900px, 110px at 2000px, 270px at 2160px, all closed by the first chunk with nothing unreachable meanwhile.
The remedy proposed here, sizing from the viewport, is the option that was considered and rejected on the merits: deriving the window from clientHeight has to guess how many rows fill the viewport before mounting any of them. The alternative it is measured against paints nothing at all for 1318ms at 2160px and then the whole thread at once. 270px of band for a third of a second at a height that needs a 4K panel in portrait is the better trade, and 16 is also what LibreChat ships for the same job.
So this is a tuning preference against a documented trade-off rather than a correctness bug.
…eopen paint floor Sizing the first commit on renderable rows walks back across every message that does not render, and that walk was unbounded: sixteen visible messages followed by two hundred system entries walked to index zero, so the commit rebuilt every provider in the thread. That is the bound this window exists to create, so cap the span at four tails. A thread has to be three quarters non-rendering across its whole tail before the cap binds; below that the window is exactly the renderable-row one. When it does bind the first commit shows whatever renders inside the cap and widening reaches the rest within a few frames, which is bounded either way. The heavy-thread smoke declared a fixed floor of one double-rAF wait for 'reopen ms'. That was right while the tail arrived in a single commit. The mount window brings a long thread back over several frames, and 'reopen ms' runs until the message count is whole, so it now spans one wait per commit: one at 25K and ten at 100K. Read the count the reopen loop already reports instead of declaring it, and resolve the declaration per row so a hand written literal is still caught when it drifts.
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…croll anchoring back removeProperty empties the inline declaration but keeps the attribute, so a converged viewport carried style="" where the shipping one carries no style at all. Inert, but it was the only difference a whole-document structural digest could find between this branch and its merge base at 100K and 300K: 45,014 normalized lines, one changed line, against a null control that scored exactly zero. Byte-identical is worth being able to state rather than footnote. Both hand-back paths now go through one helper, and the test asserts there is no second removeProperty outside it, so a future path cannot reintroduce the residue.
|
Re-measured this independently on a second machine, with a concurrent same-commit null control in UI idempotency: holds. Whole-document structural digest of the settled viewport after close, Nothing visibly reflows either. The bottom gap is 194px on the first painted frame and 199px after, Performance. The win reproduces in shape and roughly in ratio, but only as first paint, which is The largest effect is the one that was understated: longest single main-thread stall on reopen, Every other metric is inside its null: keystroke, scroll, jump, menu and delete at all three sizes, Mechanism confirmed armed from the artefact rather than assumed: Two things do change under the reader and I would rather state them than have someone find them. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6af84c8907
ℹ️ 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".
| # still worse than either: that left a full ~33ms vsync floor of constant baseline in | ||
| # both ends, which compresses the ratio towards 1 and can report a real reopen curve as | ||
| # flat when the smallest fixture rebuilds near the floor. | ||
| ("reopen ms", _action("reopen", "ms"), _floor_from("reopen", "paintWaits")), |
There was a problem hiding this comment.
Keep progressive frame latency in the reopen metric
When longer threads require more widening frames, paintWaits grows with thread size because these double-rAF polls overlap the application's own rAF-driven progressive commits. Subtracting every wait from reopen ms therefore removes real, size-dependent convergence latency rather than just the constant delay needed to observe a completed reopen, distorting the growth ratio and potentially making a regression appear flat. Keep the progressive-frame time in this metric and subtract only the final observation floor, if any.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and it is worse than a distorted ratio: it inverted the sign. Fixed in b4b38c0.
paintWaits is a property of the application, not of the instrument. The poll shares the rAF queue with the mount's own commits, so the count is 1 on a single-commit rebuild and 1 / 8 / 24 at 25K / 100K / 300K on this head. Subtracting all of them removed 33.3ms from the base arm's 300K cell and 796.8ms from head's. On the three-arm run in hand:
| 300K, chromium | base | head |
|---|---|---|
raw reopen ms |
2184.1 | 2329.7 |
| old, minus every wait | 2150.8 | 1532.9 |
| corrected, minus the observation wait | 2150.8 | 2296.5 |
So a reopen that is 6.8 percent slower read as 28.7 percent faster, and the 25K -> 300K curve read as 5.07x against base's 7.08x when it is really 7.60x, steeper than base rather than shallower.
Only the terminal observation wait comes out now, and as a constant: reopen is driven by a React state update, so the count check straight after openThread() always still sees the unmounted tree and the loop always waits out exactly one paint before a finished reopen is observable at all. Everything past that one is a frame the application spent committing rows.
reopen wall ms had the same defect through the generated wall axes, which take the recorder window's paint_waits (2 -> 25 across the ladder on head). WALL_FLOOR_OVERRIDES pins reopen to its two terminal waits, one per loop, and leaves every other action on the measured count, where those waits really are the harness idling between driven steps. The paintWaits check is now a lower bound rather than equality, so subtracting a floor the metric never waited out is still a failure while paying more waits than are subtracted is not.
Re-measured on the corrected metric, five repetitions, three arms concurrent, same-commit null:
| chromium | 100K | 300K |
|---|---|---|
| convergence, head vs base | 0.96x | 1.21x |
| concurrent null | 1.02x | 1.09x |
At 300K that is about 1.11x net of the null, against 1.20x from an independent probe that does not use this harness at all and carried a -0.7 percent null. The convergence figures in the PR body were read from raw reopen.ms rather than from the floored growth report, so they are unchanged by this; what changes is the growth ratio the harness itself prints and gates its discrimination check on.
… metric
`reopen ms` had its paint floor read from the run: `_floor_from("reopen",
"paintWaits")` subtracted one ~33ms vsync floor for every double-rAF wait the
poll loop paid. That is right only while the wait count is a property of the
instrument. It is not. The loop polls in the same rAF queue as the application's
own commits, so on a build that brings a long thread back over several animation
frames the count is a property of the APPLICATION: 1 on a single-commit rebuild,
and 1 at 25K, 8 at 100K, 24 at 300K on a progressive mount.
So the subtraction was asymmetric between the two arms of a comparison and grew
with the axis being varied. On the 220-message fixture it removed 33.3ms from
the single-commit arm's 300K cell and 796.8ms from the progressive one's, which
turned a reopen that is 6.8% slower into one that reads 28.7% faster, and turned
a 25K -> 300K curve that rises faster than the single-commit build's (7.60x
against 7.08x) into one that rises slower (5.07x). A floor removes a constant
the instrument adds; the moment it tracks the thing being measured it stops
being a floor and starts being the measurement.
Only the observation floor comes out now, and it is a constant: reopen is driven
by a React state update, so the count check straight after openThread() always
still sees the unmounted tree and the loop always waits out exactly one paint
before a finished reopen can be observed at all. Every wait past that one is a
frame the application spent committing rows and stays in the number.
`reopen wall ms` had the same defect through the generated wall axes, which take
the recorder window's measured `paint_waits` (2 -> 25 across the ladder on head).
WALL_FLOOR_OVERRIDES pins reopen to its two terminal observation waits, one per
loop, and leaves every other action on the measured count, where those waits
really are the harness idling between driven steps.
`paintWaits` is still reported and still checked, now as a lower bound rather
than as equality: subtracting a floor the metric never waited out is the failure,
paying more waits than are subtracted is the normal state of a progressive mount.
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
What this changes
Re-opening a long chat thread rebuilds every message before it can paint anything. #9016 measured
that at 3175ms on Chromium for a 300K-character thread, of which 2817ms is script, growing
7.1x from 25K to 300K. Nothing about it is incremental: the thread unmounts in 85ms and then
rebuilds 220 messages, 43,422 DOM nodes and 77 Shiki fences from nothing.
This bounds the first commit to the last 16 messages and mounts the rest 32 per animation frame,
then drops the restriction. Nothing ever unmounts. The document converges to exactly the tree
that shipped before, a few frames later.
Read the metric, not the headline. The win is first paint. Time until the whole thread is back
gets 13 to 18 percent WORSE, and that column is in the table rather than 100 lines below it because
the improvement is easy to restate as "thread reopen got 10x faster", which is not what this does.
It is the deliberate trade: a progressive mount does strictly more commits than one big one.
Re-measured independently on a second host, three arms concurrent with a same-commit null control:
first painted row 1542.2 -> 212.0ms (0.14x, a 7.3x win), full convergence 1542.2 -> 1845.6ms
(+19.7%), null -0.7%. Longest single main-thread stall on reopen, which is where the jank actually
lives, 2175.8 -> 294.9ms (-86.4%) against a null of -11.8%. The absolute before-figure is
host-dependent by a factor of 2 to 3, so read the ratios and not the milliseconds; that second box
is 2 to 3x faster than the one that produced 4289. Every other action metric (keystroke, scroll,
jump, menu, delete, at 25K, 100K and 300K) sits inside its own concurrent null.
UI idempotency, checked before any timing was read
Whole-document structural digest of the settled viewport after close then reopen then full settle,
generated ids normalized, tag boundaries newline-split so differences are countable. Five reps per
arm, three arms concurrent: two independent builds of the merge base, and this head.
The null's own score is zero, so one line is genuinely above the floor rather than lost in it.
That one line was
style=""left on the viewport root byremoveProperty, an empty attribute withno rendered effect; computed
overflow-anchorwasautoon both arms. Fixed in 6af84c8, so theconverged document is now byte-identical. Everything else already matched exactly across all five
reps of all three arms: rows 220/220, 38,752 DOM nodes, 55
<pre>, 35,086 highlighted tokens, 33images, 22 tool parts, 22 artifact cards, scrollHeight 120,402, scrollTop 119,502.
What a reader sees during the window, per-frame trace at 300K: the bottom gap is 194px on the
first painted frame and 199px thereafter, and the merge base's own single frame is also 194 then
199, so none of that band belongs to this change. No white gap is ever shown. The row a
bottom-parked reader is looking at drifts 5px total over 47 frames and 1.65s. With a real wheel
gesture against a detached reader, total drift is 3,195px on head and 3,195px on base, max per-frame
shift exactly one wheel notch on both: inserting 204 messages above a scrolling reader adds 0px.
Two things do change under the reader, stated rather than buried. The scrollbar thumb steps from
about 12 percent of the track to 0.75 percent in 8 visible steps over 1.65s as scrollHeight grows.
And for those 1.65s the thread reports its own length as 16, then 48, then 80 messages, so a reader
who drags to the top inside that window reaches something that looks like the start and is not. The
merge base cannot exhibit either, because it shows nothing at all until 1.54s. That is the honest
cost of the design.
Those three engines are the warm re-open. As opened, this did nothing at all for the cold open, the
first time a thread is opened in a session, because the component mounts before the messages
arrive; review caught that and it is fixed. The cold-open numbers and the fix are under "Design
notes". What it costs on a slow machine, which the tables above are not, has its own section.
Read this before trusting any WebKit result in this repo
This change found a hole in how we test, not just a bug in itself, so it goes near the top rather
than in a notes section.
Playwright's WebKit implements CSS scroll anchoring. No shipping Safari does. WebKit landed it
in February 2026 and it ships in Safari 27; every Safari and every iOS browser in users' hands
today has none. Playwright bundles a WebKit built from trunk, so
webkitin our harnesses reportsthe future behaviour. Measured directly here on a 400px scroller with 2000px inserted above the
scroll position: Chromium 151, Firefox 153 and Playwright's WebKit 26.5 all compensate in full, and
all three fire a scroll event for it.
That is not a footnote for this PR, it is the thing that nearly shipped a serious bug. Two earlier
versions of this change were correct on every engine the harness can run and wrong on the engine
Studio Desktop actually embeds on macOS. Standing in for a real Safari with
overflow-anchor: noneon the viewport, they walked a parked reader 19,259px, and 45,873px when the reader kept
scrolling. Both read as clean on Playwright WebKit.
So: real Safari and real WKWebView cannot be tested on this machine at all. It is Linux, there
is no macOS and no iOS on it, and Playwright ships no Safari. Everything labelled "webkit" below is
Playwright's build, which advertises
Version/26.5 Safari/605.1.15in its user agent, a versionthat has no
overflow-anchorin any browser a user can install. To be precise about the timeline,since "ships in Safari 27" is easy to over-read: WebKit enabled scroll anchoring in stable on
2026-02-13 (307475@main, bug 307734), and Safari 27 has it
in beta as of WWDC26. The newest RELEASED Safari is 26.6, and it, every earlier Safari, and
every iOS browser have none of it.
The
overflow-anchor: noneruns below are therefore a stand-in for an engine this machine does nothave. But it is a stand-in that can now be checked rather than assumed, because one shipping WebKit
that Desktop DOES embed is on this machine: WebKitGTK 2.50.4, which is what Tauri uses on Linux.
Driven directly through python-gi, same 400px scroller with 2000px inserted above a reader parked at
scrollTop 5000:
CSS.supports('overflow-anchor: none')overflow-anchor: noneThe last row is the whole point. On the engine Unsloth Desktop actually runs on Linux, content
inserted above the reader moves them, natively, today, and the two arms are indistinguishable
because there is no anchoring to turn off. That is precisely the behaviour the
overflow-anchor: nonestand-in reproduces, so the stand-in is now validated against a shippingengine rather than only argued for. Real Safari and real WKWebView remain untested and are stated
as such rather than implied.
Worth a wider look than this PR: any harness result on
webkitthat turns on scroll anchoring,overflow-anchor, or scroll-position preservation is currently measuring a browser none of ourusers run.
This is deliberately not virtualization
I investigated virtualizing the thread first and recommended against it. The short version:
rendering only the last 20 messages of the same fixture through
ThreadPrimitive.MessageByIndex:re-open goes to 438ms and is flat in thread length (441ms at 25K, 470ms at 100K, 438ms at 300K,
medians of 8 paired rounds, with a 25K null control reading 0.99x). That is the whole prize, and
it is all in the re-open. It buys nothing on scrolling, which Studio: let a settled thread skip the code blocks it is not showing #9047 already attributed to paint
and raster of on-screen content, layout plus style being 13.5ms of a 700ms gesture.
A virtualizer moves that into the scroll path, roughly 14 rows per 20-step gesture, about 180ms
of new script on top of the 616ms the gesture already costs.
02690339(2026-04-13,closing #23067) and reverted it ten days
later in
d56d74b3. The comment they left in its place calls it "catastrophic mount/destroythrashing", and #23990 ("it jumps back
and forth usually around my queries") was filed in between. What they run today is a tail slice
plus
content-visibility, and that has since needed a Safari UA sniff(#26805, blank messages on iOS
#26712), an explicit
contentVisibility = 'visible'override so export stopped truncating (34146ab6), and still has#28658 and
#28656 open from its height estimates.
MultiMessage.tsxis a recursive spine withevery row mounted and memoized;
react-virtualizedis in their tree but only drives composerdropdowns. Their long-thread fix,
#14901 (merged 2026-08-16), is a widen-only
progressive mount. This change is modelled on it.
notes that its virtualized composition cannot use
ThreadPrimitive.Viewportbecause the built-inauto-scroll assumes every message is mounted. Ours is 616 lines of tuned scroll logic built on
scrollHeightbeing the true content height. Virtualizing means rewriting all of it.Because nothing unmounts, none of find-in-page, selection across messages, copy-the-whole-thread,
screen readers, print or export can regress once it settles: after a few frames the DOM is the
document it was before, and that is checked rather than asserted in "The settled document is the
document that shipped before" below. During the build-in itself they see less, because the rows
genuinely are not there yet. That is the deferred-work half of the trade and it is the half worth
watching: a select-all or a find during the first few hundred milliseconds of a long thread opening
covers the tail rather than the whole conversation. Anything that must not see a partial thread
awaits
completeProgressiveMounts(); nothing in Studio reads the thread from the DOM today.The measurement
Two worktrees whose only difference is this commit, each carrying an identical copy of #9016's
harness. Four rounds per arm with the arm order alternating round to round, three repetitions
inside each run, so each cell is a median of four round-medians. Shared machine, vite dev server.
The harness's existing
reopencolumn stops when every message is back, which by design this doesnot improve. So the harness gains one column,
firstRowMs, the time from re-open to the firstpainted row, applied identically to both arms. Both numbers are below, because quoting only the
first would be quoting only the half that flatters this.
Chromium
Per-round first-row medians at 300K do not overlap: before 4199, 4379, 3921, 4817; after 307, 356,
565, 523.
WebKit and Firefox, 300K
The 25K row is the noise floor, and it should be read that way
At 25K nothing is windowed on either arm: 18 rows in the first paint on both sides, because a
20-message thread is under the 40-message floor. The code path is provably identical, so whatever
that column reads is measurement noise on a loaded shared machine. It reads 0.99x on Chromium,
1.13x on Firefox and 1.17x on WebKit, which puts the noise band at roughly plus or minus 17
percent.
That matters for how the costs below are stated, because some of them are inside that band.
What this costs, stated plainly
Total work goes up, not down. Every message still mounts. Convergence and CPU are 13 to 18
percent worse at 300K. On Chromium, where CPU can be attributed directly, task time goes 4118ms to
4742ms at 300K while reading 0.97x at 25K, so that cost is real rather than noise. The
convergence numbers on the other two engines sit inside the noise band, so the honest statement is
that convergence is not improved and is probably 10 to 20 percent worse. What changes is when the
user can see and use the thread.
It is a soft build-in rather than one hard stall, and the frame counts say so. Frames over
33ms at 300K go 4 to 10 on Chromium, 4 to 18 on WebKit and 8.5 to 35.5 on Firefox. Against that,
the worst single frame drops 6.4x, 7.6x and 7.9x: nothing blocks for four seconds any more, and
startTransitionkeeps the composer live throughout. I think that is the right trade and thenumbers to argue with are right there.
25K is untouched, by design.
The chunk size was measured, not inherited
One build driven at three chunk sizes, 300K, three rounds of three repetitions:
The headline does not move: the chunk cannot affect the first commit and does not change total
work. It only distributes the rest, trading the height of the build-in against its length. 32 is
the midpoint and is what #14901 uses; the table is in the source so the next person knows they are
choosing a shape rather than buying a speedup.
Design notes worth reviewing
One owner for scrollTop. Widening inserts rows above the viewport, so something must correct
the scroll position. The autoscroll hook already does it for free while the user is following: a
widening commit is a
childListmutation, its MutationObserver runspinIfFollowingin the sameframe before paint, and because widening only ever prepends, "pin to the bottom" and "shift by the
height inserted above" are the same pixel. So the mount window never writes scrollTop. It
reports the height it inserted, and the hook applies it only when the user is detached, which is
the one case where nothing else moves the viewport at all.
Correcting unconditionally would have been the bug: the extra write emits a scroll event, and
onScroll'sdelta > 0branch re-attaches a detached user parked within 24px of the bottom, whichdetachFromBottom()puts them in whenever the composer grows. The next widening frame would thenyank them to the bottom. The correction therefore also advances
lastScrollTopandlastDistanceFromBottomwith its write so the event it provokes reads as no movement, and it doesthat whether or not it wrote anything, which is a separate bug found in review and covered
below.
The window owns the viewport's scroll-anchoring mode, and the correction is document space.
This is the part that changed most in review and it is worth reading, because the first two
versions of it were both wrong in ways that only show up off this machine.
Version one measured the anchor's movement in document space with native CSS scroll anchoring
left on. That double-corrects: the browser has usually already moved scrollTop by the inserted
height, a document-space delta reports the insertion regardless, and applying it on top walked a
detached reader from scrollTop 22,897 to 117,104 across seven widenings and dumped them at the
bottom of a 300K thread.
Version two kept anchoring on and measured the leftover residual in viewport space instead, which
is single-digit pixels, and dropped any frame the reader had scrolled through, because in viewport
space a gesture and a layout shift are the same number. That is correct exactly while the browser
compensates, and this code is not in charge of whether it does. Two ways it does not, both
measured at 150K characters on #9016's fixture with a reader parked 4000px above the bottom:
February 2026; Playwright's WebKit 26.5 has it, which is exactly why this was invisible here.
Standing in for those builds with
overflow-anchor: none, one dropped frame walked the reader19,259px, and dropping every frame under continuous scrolling walked them 45,873px, on
all three engines.
programmatic scroll, which is what a scrollbar drag, PageUp, the arrow keys and middle-click
autoscroll all become. On Chromium 151 with anchoring available and a reader scrolling that way
through the build-in: 45,161px of drift, because those frames were both uncompensated and
skipped.
No measurement taken inside the frame can tell a compensated frame from a suppressed one, so the
browser is now taken out of the loop rather than modelled. The viewport sets
overflow-anchor: nonefor as long as the mount window is open and gets it back the moment thewindow closes, so a settled thread is exactly the thread that shipped before. With nothing else
moving scrollTop, the correction is document space, which subtracts the reader's own movement
arithmetically instead of dodging it, so no frame is ever skipped and there is nothing to
feature-probe. That is the shape #14901
uses. Same fixture, same reader, native anchoring available:
The last two rows are the two things review found after the design above landed, and both are
worth stating as design points rather than as bugfixes.
Disabling native anchoring has to happen before the first sample, not soon. Setting it from a
layout effect did not: this component is a DESCENDANT of the viewport element, so on the commit
that mounts them both React runs this subtree's layout effects before the viewport's own ref
callback and the ref is still null. Measured, computed
overflow-anchorstayedautofrom thefirst painted row at +305ms to the first widening at +803ms, and a reader who scrolled inside that
window lost 776px of it, or all 4000px if the whole gesture landed there. It is now set in the same
animation frame that captures the anchor, which runs after a paint and therefore after the ref
exists.
And with anchoring off for the duration, the compensation has to cover the whole interval rather
than only the widening commits, because nothing else absorbs a
<pre>swapping in Shiki output, aKaTeX resize or an image landing above the fold. Measured by injecting a 600px height change into
one row above a detached reader mid-build-in: the reader moved the full 600px, against 0px on the
merge base where native anchoring absorbed it. The correction therefore also runs between
widenings, one frame later than the movement, at one
getBoundingClientRectand onescrollTopread per frame. Getting that right also required the anchor to stop being the first row in the
LIST and become the first thing the reader can SEE, descending into a row taller than the viewport
to the element that actually reaches the fold: a row growing between the topmost row and the fold
moves the reader while leaving the topmost row exactly where it was, and an anchor taken there
reports a confident zero.
tests/studio/probe_progressive_reflow.pyis the probe that found it. Two of its own firstversions reported clean zeros for two different wrong reasons, so its guards are load-bearing.
The window arms on the cold open as well as the warm one, and originally it did not. This is
the second thing review changed, and it mattered more than the scroll work.
ProgressiveMessagesmounts before the history adapter has delivered anything, so the
useStateinitialiser ran atcount === 0, declined because 0 is under the floor, and the whole thread then landed in oneunbounded commit. Measured in the app opening a 220-message thread: mount at count 0, count 220
about 160ms later, same thread id, first paint carrying all 220 rows. Every number in the tables
above was taken on the warm re-open, where it did fire. The window now also arms on the commit
that first fills an empty tree, gated on the previous count being zero rather than on crossing
the floor, so it cannot window a conversation the reader is already in the middle of: a tree that
has never rendered a row has nothing on screen and no scroll position to lose. 300K, chromium,
medians of 5:
It arms on the first fill only. The history adapter delivers 0 to 220 in a single step, so that
suffices today; a future loader that streamed 0 to 5 to 220 would arm on the first chunk and
decline it as too short.
A thread that shrinks under a live window drops the restriction rather than clamping. Clamping
starttocountmakes the row map emit nothing. Measured before the fix: dropping a220-message thread to 10 while the window sat at start 204 painted an empty column for 2 to 8
frames, 37 to 146ms, on all three engines, with the 10 messages sitting in the store the whole
time. The
widenthat heals it runs insidestartTransition, which is why the blank persistedrather than lasting a frame.
A run drops the window immediately, on two gates: a reactive one for a run starting after the
window opened, and a re-check inside the rAF for one starting between commit and frame. A thread
that is already running never opens a window at all.
ThreadPrimitive.Messagesis replaced permanently, not switched. It rendersMessageByIndexProvider -> RenderChildrenWithAccessor -> ThreadMessageComponent;MessageByIndexdrops the middle one. Rendering one while windowed and the other while settledwould change the element type at that position and React would unmount and rebuild the entire
thread on the convergence commit. Output is identical either way:
RenderChildrenWithAccessoremits no DOM and thecomponentsform ignores its accessor.The escape hatch has no in-app caller today, and that is not an oversight. Every export path in
Studio reads
thread.export()from the runtime store, and the store was never gated. I grepped forDOM readers of the thread (
[data-role], html2canvas,window.print) and there are none.completeProgressiveMounts()is there for #9016's DOM census and for the next consumer that readsthe document instead of the store. Review found it did not work: it sampled the completer set once,
and the completers register from an effect, so a caller in the same task as the open returned in
0.1ms with 16 of 220 rows in the document. It now drains across frames, and an empty set is only
believed after 400ms of looking, because a settled thread and a thread whose history is still
loading present the same empty set. A caller on a settled thread therefore pays 400ms, which is
the right direction to be wrong in when the alternative is exporting a conversation that is not
there yet.
The
resetKeyre-arm branch is unreachable in the app today, and it is kept anyway.<GeneratedImageOverlayProvider key={runtimeThreadId}>wraps this subtree, so a thread switchdestroys and rebuilds the component and the window re-arms through the
useStateinitialiserinstead. Confirmed three independent ways: zero arm records from that branch across in-app
switches, a fresh instance at every switch, and the viewport DOM node recreated each time. It is
kept rather than deleted because it is what makes the component correct on its own terms, remove
that ancestor key and it is the only thing standing between a thread switch and the previous
thread's window gating the next one, and it is exercised by the unkeyed control in the edge probe
rather than left untested. The comment on it says all of this, so it does not read as a live
safeguard.
What this costs on a slow machine, which is where users are
The tables at the top are an unloaded desktop. The costs move with CPU speed and the benefits move
further, so both are stated. Chromium CDP throttling first, 300K, medians of 4 alternating rounds:
CDP throttling is Chromium-only, so for the other two the machine is made slow instead of the
renderer: both arms pinned to a single core, alternating, medians of 2 rounds of 3 repetitions.
300K, one core, against the current merge base:
The WebKit head arm crashed on the last round of the final pass, so its two figures are carried
from the previous pass on the same commit range and are marked here rather than quietly merged.
So the honest summary of the trade on slow hardware: the first-row win gets bigger, the
convergence penalty gets bigger, and the frame-count regression gets bigger. I think it still
holds, and more strongly than on a fast machine, because the thing on the other side of the trade
is a single unbroken 8433ms frame on Firefox during which nothing on the page responds at all.
Forty-seven slow frames you can read, scroll and type through are better than one eight-second
freeze. That is a judgement, and the numbers to argue with are above.
What it looks like
Same fixture, 220 messages, 310,603 characters, Chromium, merge base on the left and this branch
on the right. Absolute milliseconds are higher than a packaged Studio's because these are vite dev
servers running React in development mode; the ratios and the differences between the halves are
what they support.
The first painted frame, 400ms after the same re-open. The left half has painted nothing since
before the open was asked for. The right half is already showing the tail of the thread. This
difference is the whole point of the change.
Rows on screen at 0, 400, 1000, 2000, 3000 and 4000ms: before 0 / 0 / 0 / 0 / 220 / 220, after
0 / 16 / 48 / 112 / 208 / 220.
The same thread once it has settled. Indistinguishable, and every census number equal:
220 messages (110 user, 110 assistant), 43,224 DOM nodes, 55 code blocks, 35,086 highlighted
tokens, 22 tool parts, 22 collapsible outputs, 22 artifact cards, 33 images, 110 action bars, 663
tooltip triggers,
scrollHeight118,004,scrollTop117,104, top visible row #217 of 220 on both.Scroll position on open, which is what a reader notices first. The reader wheels 4000px up
while the build-in is still running. The picture can only show that two halves differ; the numbers
say which is right, so they are in the label.
That third panel is a bug this evidence found and it is fixed in 896d425, which is later
than the build in these images. The
overflow-anchor: nonethe correction depends on was beingset from a layout effect, and this component is a descendant of the viewport element, so on the
commit that mounts them both React runs this subtree's layout effects before the viewport's ref
callback: the ref was still null and the style was silently skipped until the first widening.
Measured, computed
overflow-anchorstayedautofrom the first painted row at +305ms to thefirst widening at +803ms, and a reader who scrolled inside that window lost 776px of it, or all
4000px if the whole gesture landed there. It is now set in the same animation frame that captures
the anchor, which runs after a paint and therefore after the ref exists. Re-measured on the fix,
300K, three repetitions, with the entire 4000px gesture inside the first mount window while
110,625px of content is inserted above the reader: parked at 4000px from the bottom, ends at
4028px, worst single frame 4px.
The settled document is the document that shipped before
The safety claim, checked rather than asserted, against current
main. #9016's fixture at 300K,220 messages, both arms, several seconds after the build-in completes:
innerText, sha256innerHTML, sha256scrollHeightoverflow-anchorauto, no inline style left behindEvery other census field the fixture records is equal too: messages, user and assistant messages,
code blocks, highlighted tokens, tool parts, collapsible outputs, code execution panes, artifact
cards, images, katex nodes, action bars, tooltip triggers.
Everything withheld comes back, and here is what a reader waits for
Worth being explicit, because it is the opposite of how a virtualizer behaves: mounting here is
driven by time, not by scrolling. A row arrives because the next animation frame arrived, whether
the reader scrolls or not, and once it is mounted it stays. Scrolling neither mounts anything nor
unmounts anything. The jumps below are a stress test of that claim, not the mechanism.
Deferred work is the trade; missing content would be a bug. So this measures both ends of it. The
reader re-opens the 300K thread and jumps to the TOP forty times while the build-in is still
running, then settles. The needle is a string that exists only in the FIRST message, which is the
last one the window admits, and it stands in for find-in-page, which Playwright cannot drive.
Chromium, three repetitions:
mainscrollTopafter jumping to the topSo nothing is lost and the reader ends up at the true top of the thread, having asked for it while
it was still building. What it costs is stated in the second row and it is the one number in this
PR that is worse for a reader who is looking for the OLDEST message: at 300K they wait about a
second longer for it than they do today, while everything they can actually see arrives about five
times sooner. A find-in-page issued during those few seconds covers the tail rather than the whole
conversation. Anything that must not see a partial thread awaits
completeProgressiveMounts();nothing in Studio reads the thread from the DOM today.
Tests
studio/frontend/tests/progressive-mount-controller.test.ts, 12 tests over the pure state machine,including that the window only ever moves
startdown, that it always reachesnull, and that awindow left pointing past the end of a thread that shrank is dropped rather than painting nothing.
studio/frontend/tests/progressive-mount-glue.test.ts, 13 source assertions over the parts thatare not pure (the glue is a
.tsxand node's type stripping cannot import one, the same reason andshape as the existing
chat-autoscroll-frame-budget.test.ts). Each names the failure it protects:the primitive swap that would remount everything, rows hidden rather than withheld, the mount
window writing scrollTop itself, the correction not advancing the intent bookkeeping, a
document-wide viewport query that would find the wrong Compare pane.
tests/studio/probe_progressive_anchor.pyis what found the scroll bug above, and it is includedhere. It re-opens a 300K thread, scrolls the reader up with a real wheel once the first widening
has landed, and samples the anchored message every frame until convergence. It is worth saying that
its own guards did the work: the first three versions of it silently measured the pinned branch
instead of the detached one, and each time the end-of-run check ("the reader was not detached and
this measured the pinned branch instead") refused to report rather than printing a clean zero.
It needs #9016's fixture page, which is the same dependency the whole measurement above has, so it
cannot run in CI until that lands.
npm test2962 passed,npm run typecheckclean,npm run buildclean, biome reports zero errorson both new source files.
Notes for review
biome-ignoreinprogressive-messages.tsx, onuseExhaustiveDependencies.mountWindowis the trigger for the layout effects rather than a value their bodies read, so the rule cannot
see it; dropping it would run them once and never correct a shift again.
actively misleading. See the section at the top; it is the most important thing in this PR.
currently carrying 35+ pending checks per PR. Green on all of: Workflow trigger lint, Unsloth UI
CI, Unsloth API CI, Unsloth GGUF CI, Windows Unsloth UI CI, Windows Unsloth API CI, Windows
Unsloth GGUF CI, Mac Studio GGUF CI, Mac Studio UI + API + Update CI. So ubuntu-latest, macos-14
and windows-latest all pass. The staging PR is closed, never merged.
firstRowMsis not in Studio: measure where a heavy thread stalls, across engines and thread size #9016's harness onmain. Every measurement above used an identicalpatched copy in both arms. It is worth folding into Studio: measure where a heavy thread stalls, across engines and thread size #9016 so this stays measurable, and I have
not done that here to keep this diff to the change itself.
The composer during the build-in, which is the one number that got worse
An earlier head showed a Firefox composer regression, 36ms to 106ms median, and this PR carried it
as an open question because it predated the scroll rewrite. It is now re-measured on the current
head and it is real. Firefox 153, 220 messages, this branch against the merge base, arms
alternating, two rounds of three repetitions each:
Read the last two rows before the first three, because they are what the first three mean. On the
merge base the re-open is one blocking commit, and in all six merge-base repetitions every
keystroke landed with all 220 rows already in the document. The probe cannot even start typing
earlier: the call that focuses the composer does not return until the commit is over. So the
merge base's 35.5ms is not typing through a rebuild, it is typing after one, and the same run
records a 3237ms unbroken stall where that typing could not have happened.
The honest form of this is therefore not "35ms became 92ms". It is that a window in which nothing
could be typed at all became a window in which typing works at 92ms median, and a 3237ms stall
became a 337ms one.
startTransitionis what buys that, and 92ms is what it costs.Once the thread settles the two are identical. #9016's harness measures the composer on a settled
thread by construction, and at 300K characters on Firefox over four alternating rounds of three
repetitions it reads 34.0ms on both arms (round medians 33, 35, 34, 34 against 34, 34, 34, 33),
which is the 33 to 34ms double-rAF paint floor both arms were already sitting on.
Chromium and WebKit were not re-measured on this head and still carry the earlier head's numbers.
The reopen number an external study reported, reconciled
A performance study run against a frozen
mainon real Desktop hardware, with CPU throttlingdisabled, reported this branch as inconclusive on its 300K reopen cell, with the medians moving
the wrong way, chromium +15.5% (n=3/3) and firefox +13.6% (n=3/3), samples overlapping the observed
spread. Reopen speed is the point of this branch, so that needed an answer rather than a footnote.
That metric measures full convergence, not first paint. Its reopen clock starts immediately
before
openThread()and stops the first frame on whichmessageCount() >= before, wheremessageCount()isdocument.querySelectorAll("[data-role]").length. The stop condition is "all220 rows are back in the document". A change that puts the first rows on screen sooner while the
tail arrives later is invisible to it by construction, and in fact scores worse, because a chunked
mount does strictly more commits than one big one. So the study's number is a convergence
regression, and it is real. It is not a statement about when the user first sees anything.
The study's own raw output already contains the other half. On the base arm it logs 7 rAF
callbacks across a 1.8s window with a single 1668.9ms frame. Seven frames in 1.8s is a renderer
that painted nothing.
Both quantities, measured here on the merge base against this head, 300K characters, 220 messages,
six alternating repetitions per arm in one browser process, every repetition gated on the thread
actually unmounting before it is re-opened, and gated on both arms agreeing on highlighted-token,
DOM-node, code-block and message counts before any timing is taken:
The structural fact that settles it: on the merge base, first paint and convergence are the same
instant, 2554 against 2554ms on chromium and 3143 against 3149ms on firefox. The base has no
progressive behaviour at all, so it freezes and then commits all 220 rows in one frame, which is
why the study's convergence metric happened to also be its first-paint metric on the base arm and
is not on this one. That is the entire disagreement.
So the trade is an 8 to 10x improvement in time to first paint, and the removal of a 2.5 to 3.1
second frame in which the renderer cannot paint at all, against a last row that lands later.
Three things about that table are weaker than the rest and should not be quoted as though they
were not.
The chromium convergence delta is soft. A gated run gives +5.5% and an earlier run gave +14.3%.
The base is stable across runs (medians 2554 and 2557) and the head is not (2695 and 2922, an 8%
swing). Pooling all twelve repetitions per arm gives +10.3% with base spanning 2387 to 3038 and
head 2579 to 3082, which overlap. On chromium the direction is a regression and the magnitude
is no tighter than roughly 5 to 15%. Firefox is the cleaner arm and its +17.7% is only barely
non-overlapping (base max 3505, head min 3463).
The first-paint result is not soft: pooled chromium base 2386 to 3038ms against head 279 to
406ms, and firefox base 3085 to 3499ms against head 300 to 406ms. No overlap on either engine.
#8992 was in neither arm when that table was taken. It is in both arms now, and the question
it raised has been answered. #8992 is +247/-33 in
thread.tsx, the same file this branchchanges, and the same study rates it a confirmed improvement on this very convergence metric
(chromium -29.8%, firefox -31.0%), so its win and this branch's cost were originally measured
against bases that each lacked the other. #8992 then merged to main as
b0843382d, and thisbranch's head is a merge of main, so both the merge base and the head now contain it. Re-measured
on that footing, 12 interleaved repetitions per arm per engine: the cost survives, at
chromium +17.0% with the ranges disjoint and firefox +12.0% with the ranges overlapping on one
of twelve pairs, which by the min-max rule used throughout this description is not resolvable.
The band is unchanged, so #8992 neither absorbs the cost nor amplifies it. Note this reverses which
engine is the clean arm: with #8992 present chromium is the disjoint one and firefox the soft one,
the opposite of the table above. Full numbers, the discrimination check and the remaining loose end
on firefox cold reopens are in the comments on this PR.
Absolute milliseconds here are about 1.5x the study's, on different hardware and a different
viewport, so only the within-run base-against-head comparison is meaningful. Do not read my
milliseconds against theirs. WebKit was not re-measured for first paint; the study's WebKit cells
corroborate the direction (worst frame 1732ms base against 208ms head) and that is all I have there.