Repository navigation
Studio: reduce long-chat panel and scrolling lag on Linux - #16854
danielhanchen merged 12 commits into
Conversation
|
The other 8 only fail here, in tests that pin the code fence and message window behaviour this PR reworks:
Either the new code drops one of those contracts (find-in-page over a skipped fence looks like the main risk) or the tests need updating to the new structure. A rebase onto main will clear the label failure. |
…s are added (#16856) ## Summary From 21:00 UTC yesterday until #16809 merged, `Frontend unit tests (Windows)` and `Frontend build + bundle sanity` failed on every frontend PR (#16826, #16829, #16831, #16839, #16854 and others) with the same test: ``` not ok 4712 - family options follow the backend registry, deduplicated, and every backend family has a label location: 'studio/frontend/tests/family-override.test.ts:54:1' + [ [ 'chroma', 'chroma' ], [ 'anima', 'anima' ] ] - [] ``` #16710 added the `chroma` and `anima` image families to the backend registry. That part is fine, and #16809 added the missing picker labels. The test caught it correctly, but on the wrong PR: it reads `diffusion_families.py` and `video_families.py`, yet only Frontend CI runs it, and Frontend CI only triggers on `studio/frontend/**`. So the backend-only PR that added the families never ran it and merged green, and the next frontend PR inherited the failure. ## Change `studio/backend/tests/test_family_override_labels.py`, a new test only. It takes every family name from `diffusion_families._FAMILIES` and `video_families._FAMILIES`, reads the keys of `LABELS` in `family-override.ts`, and fails if a family has no label, naming the missing ones. Backend CI triggers on `studio/**`, so the PR that adds a family now has to add its label too. A second small test pins the `LABELS` parser on quoted (`"flux.1":`) and bare (`sdxl:`) keys, so a reformatted table cannot quietly read as empty. Running Frontend CI on every family registry change would also work, but those files change many times a day and the frontend jobs include Windows and macOS legs. One backend test costs under a second. No product code changes, and the frontend test stays as it is. ## Testing - On main (with #16809): 2 passed. - Deleting `chroma: "Chroma"` from `LABELS` again: fails with `add these families to LABELS in family-override.ts: ['chroma']`. - The file sorts into the existing `a-f` backend shard by glob. `tests/test_ci_backend_pytest_shards.py`: 26 passed.
# Conflicts: # studio/frontend/src/features/chat/chat-page.tsx [skip ci]
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
… WebKitGTK windowing The highlight-queue observer only flushes when find opens, so watching the code wrap and line-number flags there did nothing; restore its filter to the find flag alone. The window remeasure observer keeps the wider filter, which offscreen plain fences need. Update the source-pinned tests for the new expressions: the windowed attribute is still set only once a fence is measured, the anchor walk still checks visibility before reading a rect (now through display: contents wrappers), and the context panel stays collapsible with the browser off WebKitGTK.
…ences skipped mid-drag A parked message keeps the height it had when parked. After the chat narrows, reconnecting it above the viewport changes its height and the visible content jumped. The window controller now records the first visible row before reconnecting or releasing heights and scrolls by however far it moved, which is zero when the engine anchored natively. The layout read is skipped when nothing was reconnected. An offscreen fence whose update is skipped while the pointer is held or a selection touches it now marks a held frame, so pointer release and selection changes remeasure it instead of leaving visible code as plain text.
…l owner The restore correction wrote scrollTop directly, which animated under the viewport's scroll-smooth class and left the autoscroll hook's lastScrollTop stale, so a detached reader near the bottom read as scrolling down and was re-attached. WindowedMessageBody now passes adjustForContentInsertedAbove to the window controller, which applies the correction instantly and resyncs follow intent. Without a provider the controller falls back to an instant scrollTo.
…ng is on Line windows map scroll offsets to source lines with one unwrapped row per line. With code wrapping on, a source line spans several rows, so the window ran ahead of the reader and the visible lines rendered without highlighting. Settled fences on WebKitGTK now window only while data-code-wrap is off, read through one shared MutationObserver so toggling the setting takes effect immediately.
…n height is released After the chat narrows, a parked reply reconnected while the native thumb is held keeps its pre-resize height but reflows taller, and nothing clipped it, so its text painted over the next messages until release. The frozen row now also sets overflow clip (hidden where clip is not supported) and saves the original overflow, which release restores with the height.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d06ab8359d
ℹ️ 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".
| windowing: boolean; | ||
| }) { | ||
| const codeWrap = useCodeWrap(); | ||
| windowing ||= WINDOW_SETTLED_FENCES && !isIncomplete && !codeWrap; |
There was a problem hiding this comment.
Retain token batching for fences below the line-window cap
For a settled WebKitGTK fence containing a dense line, such as minified JSON with more than 4,096 tokens, this enables windowing even when the fence has at most 240 lines. useLineWindow() then returns no window, while useFenceHighlightLimit() treats windowing as ineligible for staged highlighting, so the FenceLine branch renders every token at once. A 10,000-token line therefore bypasses the existing 512-token quiet-work batches and creates a large synchronous React/DOM commit when reached. Keep the batched rendering path below the line-window cap, or preserve token budgeting within the windowed path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 61424fe. WebKitGTK now only forces windowing for settled fences over WINDOW_CAP_LINES, where a line window actually exists, so fences under the cap keep the batched highlight path (dense single lines included).
| // over the next messages; release restores the original overflow with the height. | ||
| if (freeze) { | ||
| const style = row.root.style; | ||
| row.frozen = [...row.saved, ["overflow", style.getPropertyValue("overflow"), style.getPropertyPriority("overflow")]]; |
There was a problem hiding this comment.
Preserve original overflow across repeated thumb restorations
On WebKitGTK, drag the native thumb into a parked row, away far enough to park it again, and back into it before releasing. apply() carries the first frozen snapshot into row.saved, so it already contains the original overflow value; appending another entry here captures the temporary clip as a second value. releaseHeight() replays both entries and leaves the row permanently overflow: clip, including after cleanup, so normal message overflow remains clipped after the drag ends. Reuse the existing overflow snapshot rather than appending another one on each restoration.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 61424fe. restore() reuses the existing overflow entry when the saved snapshot already carries one, so a row parked and restored again in the same drag releases its original overflow. Added a test that parks, restores, parks and restores in one drag; it fails on the previous controller.
…ep the original overflow across repeated thumb restores [skip ci]
|
@codex review |
# Conflicts: # studio/frontend/src/components/assistant-ui/thread.tsx # studio/frontend/src/index.css
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 61424fe1bb
ℹ️ 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".
| <pre className={joinClasses(languageClass, PRE_CLASS)} style={rootStyle}> | ||
| <code className={CODE_CLASS} ref={code}> | ||
| {windowing ? tokens.map((line, index) => ( | ||
| {offscreenPlain ? <PlainFenceText source={source} /> : windowing ? tokens.map((line, index) => ( |
There was a problem hiding this comment.
Reapply token budgeting when restoring a plain fence
On WebKitGTK with wrapping and line numbers off, scrolling away from a fully highlighted dense fence below the 240-line cap removes FenceLines, but useFenceHighlightLimit remains mounted with its completed progress === null. Returning to the fence therefore remounts all its highlighted tokens in one commit instead of using the 512-token quiet-work batches, potentially recreating thousands of spans during scrolling. The cap guard now protects initial rendering, but not this new offscreenPlain restoration path. Reset or reapply the rendering budget when returning from plain text.
Useful? React with 👍 / 👎.
| if (selected || inputPointerHeld()) { | ||
| // Retry on pointer release or selection change, which remeasure only after a held frame. | ||
| heldLastFrame = true; | ||
| return; |
There was a problem hiding this comment.
Retry offscreen fence updates after touch release
On a WebKitGTK touchscreen, bring a plain offscreen fence into view, pause with the finger down, then lift without further scrolling. inputPointerHeld() includes touch pointers, so this branch skips restoration and sets heldLastFrame; however, onPointerDown() explicitly ignores touch events, and releasePointer() returns immediately when its mouse-only pointerHeld is null. Consequently, lifting the finger schedules no retry, leaving the visible fence unhighlighted until another scroll, resize, or selection event. Include touch releases in the retry mechanism or avoid deferring restoration for touch input.
Useful? React with 👍 / 👎.
… pointer release (unslothai#16919) Follow-up to unslothai#16854. Two review findings on the WebKitGTK (Linux desktop) code fence paths; Chromium (Windows) and macOS never enable these paths, so nothing changes there. ## Problems 1. Scrolling back to a dense code fence below the 240-line window cap remounted every highlighted token in one commit. When the fence goes offscreen it is parked as plain text and `FenceLines` unmounts, but `useFenceHighlightLimit` stays mounted with finished progress, so coming back skipped the 512-token batches. A 120-line fence with 64 tokens per line came back as 7,680 spans in a single render. 2. A fence that came into view while a finger was down stayed unhighlighted after the finger lifted. The restore is deferred while a pointer is held and retried on release, but `releasePointer()` returned early unless a mouse press had been recorded. Touch never records one, and neither does a mouse press that began before the listeners attached. ## Fix - `useFenceHighlightLimit` takes the parked state. Parking restarts the batched progress and pauses the queue, so returning remounts one batch at a time. The reset only runs when the parked state changes, so it is idempotent. - `releasePointer()` always clears the held pointer and schedules the retry when a restore was deferred. Repeated calls coalesce into one frame. ## Tests - New `studio/frontend/tests/code-fence-offscreen-restore.test.ts` runs the real hook and listener code extracted from `code-fence-defer.tsx`: - a dense fence that is parked and restored returns at most one 512-token batch per commit, and does no highlight work while parked; - touch release, normal mouse release, and a mouse press that began before the listeners attached all restore the fence. - Each test fails without its fix (3 of 4 fail on main; the normal mouse case already worked). - `desktop-webkit-paths.test.ts` updated for the new `releasePointer` body. - 108 of 108 tests in the 13 files that read `code-fence-defer.tsx` pass; `tsc -p tsconfig.app.json` is clean.
…tory in larger steps (unslothai#16924) Follow-up to unslothai#16854. On the Linux desktop app (WebKitGTK), loading a long chat's history became about 60 to 80% slower after unslothai#16854, because history was mounted 2 messages per frame for the whole thread (about 142 commits instead of about 9 for a 150-turn chat). The first messages appeared at the same time; the extra time was the background history load, with about 150 frames over 50 ms instead of about 30. ## Fix WebKitGTK only. Each widening step measures how far the first mounted row is above the viewport top (read after the existing anchor capture, so no extra layout pass): - Within the window controller's reach (2000 px), rows stay unparked and can move what the reader sees, so they still mount 2 per step, as in unslothai#16854. - Past it, rows are parked as they land, so the step ramps 2, 8, 16 and holds at 16 (`FAR_MOUNT_CHUNK`). The first step of every load stays at 2 so the tail paints as early as before. - Coming back within reach drops straight to 2. Pausing during scroll, typing and pointer drags, `flushSync`, and the anchor correction are unchanged. Chromium (Windows) and macOS never call the new path; their step stays `CHUNK_MESSAGES`. The cap is 16 rather than 32 on purpose: 32 brought the load time back to within 2 to 6% of before unslothai#16854 with Glass off, but made single frames up to about 1.4 s on CPU-painted WebKit. 16 keeps the worst frame at the level of the 2-per-step loader. ## Results GitHub ubuntu-latest, Playwright WebKit, 150-turn heavy chat, time until all 300 messages are mounted, per-runner medians of 3 loads (two runners of different speed): | | Before unslothai#16854 | main | This PR | |---|---|---|---| | Glass off, runner a | 13.6 s | 21.3 s | 15.1 s | | Glass off, runner b | 8.1 s | 13.2 s | 9.2 s | | Glass on, runner a | 14.4 s | 24.5 s | 17.0 s | | Glass on, runner b | 8.5 s | 15.6 s | 10.2 s | - First messages appear on the same frame as main (the first step is 2 rows on both). - No reader shake: the message at the middle of the viewport did not move by 1 px or more in any load, the same as main. - Chromium loads identically to main (all 300 messages at 5.6 s, 32 per step in both). ## Tests - `progressive-mount-controller.test.ts`: the step stays small near the reader and for unknown geometry, ramps 2, 8, 16 past the reach and holds, drops back when the reader returns, never changes the step on other engines, and covers a 300-message thread in about 20 commits instead of about 142. - Glue tests pin that only WebKitGTK takes the adaptive step. - 72 related tests pass; `tsc -p tsconfig.app.json` and `node scripts/typecheck.mjs --tests` are clean.
…t on long chats (unslothai#16986) ## Problem Opening the browser pane narrows the chat column from about 1018 px to 509 px, and every message in the thread re-wraps at the new width. On real `macos-15` runners at 150 turns (300 messages, about 56k nodes) the pane takes 1.09-1.85 s to open, with single frames of 0.73-1.25 s. On macOS Chromium it takes 369-713 ms, 423 ms of that layout. Closing pays the same re-wrap again. ## Fix - `distant-rows.ts`: an IntersectionObserver marks message rows further than max(1500 px, 2x the window height) from the viewport with `data-row-distant`. The reach stays ahead of Chromium's own `content-visibility: auto` activation margin (150% of the window height), so a row is released, and its re-wrap compensated, before the engine renders it. WebKit uses no margin. The observer is rebuilt when the window height changes. `index.css` gives those rows `content-visibility: auto`, so a width change only re-wraps the rows near the reader. - Every row carries `contain-intrinsic-size: auto 600px`, so a skipped row keeps the height it last rendered at and the scrollbar does not move. The 600 px estimate only applies to a row that never rendered. - A row is skipped only after it has stayed distant for two frames, once the engine has recorded its size. - Whenever rows are skipped or released, the first visible row is held in place through the existing autoscroll owner. A reader pinned to the bottom stays pinned, and a reader scrolled up does not jump when old rows re-wrap at the new width. - Skipped rows get `flex-shrink: 0`: Chromium otherwise shrinks a size-contained flex item below its remembered height. - Rows that own horizontal scroll range, and rows with numbered equations (their counters run across messages), are never skipped. Print shows every row. - Select All (Cmd/Ctrl+A outside an input) releases every skipped row through the same anchored path first, so the reader does not jump when the browser lays them out to select them. - `message-row-containment*.ts`: gated like the existing containment flags, so it can be turned off at runtime with `__UNSLOTH_MESSAGE_ROW_CONTAINMENT__`. On in Chromium (Windows WebView2) and Safari 26+. Off on Linux WebKitGTK, where `message-window-controller.ts` (unslothai#16854) already parks distant rows. - `code-fence-defer.tsx`: the idle highlighter ranks fences inside a skipped row by the row's box instead of the fence's. Reading the fence forced Chromium to lay out the skipped row on every idle pass. ## Results Local, 150 turns (300 messages), base and head interleaved, 3 runs x 3 toggles, median [min-max] ms: | Engine | Measure | main | This PR | |---|---|---|---| | WebKit (mac UA) | Pane open, longest frame | 749 [719-1645] | 96 [65-342] | | WebKit (mac UA) | Pane open, total time in frames over 50 ms | 1484 | 309 | | WebKit (mac UA) | Pane close, longest frame | 702 [671-725] | 68 [53-170] | | Chromium | Pane open, longest frame / layout | 133 / 123 | 33 / 25 | | Chromium | Pane close, longest frame / layout | 133 / 80 | 17 / 14 | | Chromium | Forced layout when the column halves | 97 | 4 | Real GitHub runners, 150 turns, both arms on the same runner per rep (2 reps, alternating order): | Engine | Measure | main | This PR | |---|---|---|---| | macOS WebKit (`macos-15`) | Pane open, total (longest frame) | 1463 (990) / 1625 (968) ms | 699 (299) / 751 (326) ms | | macOS Chromium | Pane open, longest frame | 333 / 317 ms | 100 / 133 ms | | Edge (`windows-latest`) | Pane open, longest frame | 233 / 217 ms | 83 / 83 ms | | Edge | Pane layout, open / close (trace) | 342-350 / 350-387 ms | 57-62 / 44-55 ms | Typing, scrolling and Settings open/close are unchanged within noise on all three engines, and nothing got worse by more than 1.5x in both reps. Screenshots of the thread and the pane match main apart from sub-pixel text antialiasing. Locally, typing is unchanged: WebKit p50/p95 24/32 vs 27/33 ms, Chromium 12/24 vs 13/23 ms. Scrolling p50 is unchanged in both engines. WebKit scroll p95 read 26 vs 32 ms, inside this host's run-to-run spread. ## Behaviour (WebKit with a mac UA and Chromium, main vs this PR) - Scrolling up on a tall window (1400x2200) while older messages are still mounting, after narrowing the column: no jumps from this change in Chromium or WebKit (a 106 px shift on user messages also happens on main). - Pinned to the bottom after load and after opening the pane: 0 px in both, 12 of 12 loads and 6 of 6 pane toggles. - Scrolling up with the pane open through rows last laid out at the wider width: the first visible row moves at most 0.2 px (WebKit), and Chromium matches main. - The find bar finds text in an old offscreen message in both engines. Select all and copy give the same character count. - Expanding a tool block in an old message, jumping to a skipped message, and printing all behave as on main. - Streaming a reply (WebKit, mock server): the view stays pinned to the bottom, as on main. - Screenshots at the bottom of the thread are pixel-identical in WebKit. Not covered: Select All from a menu (not the keyboard) while scrolled up after the column narrowed can still jump once, since releasing every row on each `selectstart` would re-wrap the thread on every mouse selection; an old row that starts overflowing horizontally only after the column narrows adds its scroll range once it comes within reach, not while it is far away; real Safari / WKWebView and the desktop shells (local WebKit is WebKitGTK with a mac UA); streaming in Chromium; dragging the scrollbar or jumping more than 1500 px into rows skipped at a different width, which can show their re-wrap. ## Tests - New `tests/message-row-containment.test.ts` (13 tests); turning off the hold-in-place, the Select All release, the numbered-equation exemption, or pinning the reach to 1500 px makes them fail. - `math-block-containment-wiring.test.ts` counts the new `content-visibility: auto` rule. - Long-chat gate (unslothai#16931): PASS. Full frontend suite passes except the KaTeX stylesheet test that also fails on main with a symlinked `node_modules`. `node scripts/typecheck.mjs --tests` is clean.
A long chat costs the Linux app in proportion to its length, on every interaction. All of that cost is on the web process main thread (script, style recalc, IntersectionObserver); the raster and compositor threads are close to idle, with Glass on or off. `main` mounts every message and never unmounts one, so opening Settings, typing a key, switching pages and coming back each pay for the whole thread. This mounts only the rows near the reader. Two spacers stand in for the rows on either side, so the thread costs what is on screen and not its length. On all platforms, not only WebKitGTK. ## Numbers Native Tauri app, WebKitGTK 2.54.2, GPU compositing path, minified builds of `main` (9dc37ed) and this branch on top of it, measured in the same session on the same machine, in a nested offscreen KWin session at 60 Hz. The chat is the 600-message, ~911k-token scroll repro. Solid theme unless noted. "Longest freeze" is the longest gap between two animation frames after the click; medians of 3. ```mermaid xychart-beta title "Longest freeze in a 600-message chat, ms (bars: main, line: this PR)" x-axis ["Settings open", "Settings close", "Model picker open", "Run settings open", "Run settings close"] y-axis "ms" 0 --> 300 bar [273, 93, 105, 84, 72] line [109, 37, 49, 27, 25] ``` ```mermaid xychart-beta title "Seconds (bars: main, line: this PR)" x-axis ["Freeze returning from Model hub", "Jank in the 25 s after opening the chat", "Main-thread CPU in those 25 s"] y-axis "s" 0 --> 16 bar [5.06, 13.83, 15.88] line [0.09, 0.43, 1.00] ``` | 600-message chat | main | this PR | |---|---|---| | Messages mounted | 600 (599 with their bodies parked) | 1-5, about 2,300 elements in the document | | Web process memory, solid / Glass | 3.6 / 2.9 GB | 1.6 / 1.0 GB | | Settings open, longest freeze, solid / Glass | 273 / 287 ms | 109 / 134 ms | | Settings close | 93 ms | 37 ms | | Model picker open | 105 ms | 49 ms | | Run settings open / close | 84 / 72 ms | 27 / 25 ms | | Returning to the chat from Model hub | 5.0-5.3 s freeze | 0.09-0.18 s | | Opening the chat: first rows on screen | 944 ms | 379 ms | | Opening the chat: jank over the next 25 s | 13.8 s | 0.43 s | | Opening the chat: main-thread CPU over those 25 s | 15.9 s | 1.0 s | | Typing 33 keys, web process CPU | 0.65 s | 0.36 s | A real 300k-token agent chat (54 messages, 98,000 px tall) behaves the same on this branch: one row mounted, Settings open 104 ms, model picker 43 ms. Glass adds 14-25 ms to Settings open in both builds and nothing measurable elsewhere. `WEBKIT_SKIA_MSAA_SAMPLE_COUNT` 0 and 4, `WEBKIT_LAYERS_TILE_SIZE` and DDL off with GPU painting threads made no measurable difference under Glass (DDL off was worse on scroll), so none of them is set here. ## What changed **The thread window** (`thread-window.ts` for the maths, `progressive-messages.tsx` for the DOM and React side). - Rows mount within 2,000 px of the viewport and unmount past 4,000 px. Rows stay in normal flow between a top and a bottom spacer; nothing is positioned, so an append adds one node and touches nothing else. - A row that has rendered keeps its measured height. One that has not is estimated from the lines its text will render (so code is not sized as a paragraph) times what a line has taken in the rows measured so far, per role. On the agent fixture the scroll range is within 1.4% of the fully mounted thread before any row above the fold has rendered. - A height surprise above the reader is absorbed by the top spacer and not by `scrollTop`, so wheel momentum and a held scrollbar thumb are left alone. The slack is folded into `scrollTop` once input is quiet. - A thread is windowed by estimated height (40,000 px and 8 messages), not message count: an agent chat is often a few turns of very long replies. - Readers of the whole document still get it. Find, print and select all mount every row (progressively, pausing for scroll and input), and the window reopens when they are done. Each pass adds up to 32 rows each way but at most about 20,000 px of estimated height, so very long replies do not land 32 to a commit. Turn-rail jumps mount the target row directly. - Rows publish `aria-setsize` and `aria-posinset` while the thread is windowed. - A copy whose selection runs across a spacer mounts the missing rows before the clipboard is read, so the copy is never short. - The focused row, a row being edited, playing media, selected text and the reply being streamed are never unmounted. A row like that which the window moves away from stays mounted where it is, as a pin with a spacer on either side, so a scrollbar drag to the other end of the thread keeps an unsaved edit and does not mount what lies between. - A thread hidden behind another route does nothing: it has no boxes to measure. It does not count as a pending mount either, so it cannot hold up a reader of a thread that is on screen. **Root layout.** The layout re-renders when Settings opens (its open flag gates the route shortcuts), and that re-rendered the sidebar, the navbar and the chat page. Those now bail out. **Composer.** A keystroke re-rendered 297 components under the composer. The toolbar controls that never read the text are kept out of it, which leaves 68, and the input handler goes from about 3.5 to 1.9 ms per key (instrumented build). The draft, queue and submit logic is untouched. ## The recorded "do not virtualize the message list" result `tests/studio/studiobench/CONTRIBUTING-perf.md` records a virtualized list as built, measured and rejected. This PR has **not** been run through studiobench, so that record is left as it is. Each failure it lists was checked with other instruments: - **First send into a freshly opened thread got slower** (their mechanism: an end-anchored list re-renders and re-positions every mounted row, 60 ms of style recalc against 14). Here rows are in flow. Chromium, production build, 400 agent-style messages, medians of 3 fresh pages, windowed against the same build holding every row mounted: main-thread task time in the first 250 ms after send 62 ms against 243, style recalc 3.0 ms against 3.3, longest frame gap 22 ms against 63, whole 20-chunk stream 93 ms against 475. The second send costs the same as the first. - **It lost the thread on an action.** Model picker, Settings, leaving for Model hub and returning, and switching chats all keep the thread, in the native app. - **Accessibility.** `aria-setsize` / `aria-posinset` are published, as the bench's windowed readiness gate requires. - **Select-all copy was truncated.** The copy carries the whole thread: 1,985,097 characters on both builds in the native app, and equal to the fully mounted thread in the new gate. - **Scroll extent.** 1.4% from the mounted thread on open, against the bench's 10% allowance. A studiobench A/B with a null control and `--windowed-arm` is still owed before the perf claim meets that document's bar. ## Trade-offs - **Select all then copy at once on a very long chat is slower.** The rows have to exist to be copied. On the 911k-token chat that is a 14.7 s freeze against 6.2 s on `main`. `main` spends that time when the chat opens instead (about 15 s of background mounting, every time). Waiting after Ctrl+A lets it fill in the background, in passes of at most about 20,000 px of estimated height so input stays live while it runs: on 60 replies of about 5,000 px in Chromium the longest frame gap is 159 ms, against 1,097 ms with 32 rows to a pass, and the whole mount takes 4.5 s against 3.8 s. Serving that copy from the message store would remove the freeze but would copy markdown source and not rendered text; not done here. - **Find covers a very long chat over several seconds** (about 15 s on the 911k-token chat on WebKitGTK). The page stays responsive and matches appear as rows land. - **React state inside a row that scrolls far away is lost**, for example a reasoning block the reader expanded. - **One very long message is still one row.** A chat made of a few huge replies gains less. - **A fling far beyond real input speeds can outrun the window** (seen at 187,000 px/s in Chromium; covered at 75,000 px/s). It catches up within a few frames of stopping. ## Tests - `tests/studio/playwright_thread_window.py` is new and added to the frontend CI job. Structure only, no timings: the DOM does not grow from 80 to 400 messages, ordinals are published, the scroll range matches the mounted thread, wheeling to the top the window catches up after every step and passes every message, a reader at rest does not move, a jump lands on rows, a focused row keeps its node and its focus across jumps to both ends and back, a copy across unmounted rows is complete and the window reopens after it, a hidden thread mounts nothing and is not counted as pending, a streamed reply lands at the tail, and no pass of a select-all mount exceeds the height budget. Passes in Chromium and Firefox. - `smoke-thread-weight.html` and `smoke-heavy-thread.html` measure what a whole thread costs in the DOM, so they now hold every row mounted (`?window=1` on the first leaves the thread as the app opens it). The long-thread gate's area matrix and WebKit leg wait on the published thread length. - `thread-window.test.ts` covers the window maths; `progressive-mount-glue.test.ts` is rewritten for the new glue. - Frontend unit suite: 15,694 of 15,707 pass. The 12 that fail are locale and date formatting tests that fail the same way on `main` on this machine. - All 24 browser gates the frontend CI job runs pass locally in Chromium (Firefox too where the script takes engines), including the long-thread gate with its area matrix, heavy thread, find in page, chat autoscroll, stream pacing and tool activity. After rebasing onto current `main`, the typecheck, the unit suite and the window, long-chat, find, autoscroll, stream-pacing and composer gates were run again. After the review fixes (pinned rows, hidden threads, the full-mount budget), the typecheck, the unit suite and the window (Chromium and Firefox), long-thread, heavy-thread, long-chat, find, autoscroll, progressive-rows and stream-pacing gates were run again. - Native app: wheel scrolling up and down keeps the viewport covered with the reader's row within 0.1 px; jumps to the top, middle and bottom land on rows; turn-rail jumps, find, copy, Settings, the model picker, leaving for Model hub and switching chats were exercised on the 600-message chat. - Not run: the Playwright WebKit legs (WebKit cannot launch on this host; the native WebKitGTK app was the WebKit check), and studiobench. Related to #16603. Builds on #16854; the WebKitGTK body parking from that PR is left in place and now only ever sees the few mounted rows. ## Before / after in Studio Same 300-message chat, seeded through the chat history API into two fresh Studio installs (merge base `31d7eb47e` on the left, this branch at `935866a96` on the right), at the bottom of the thread as it opens and at the top after wheeling up. At the bottom: both show Reply 148 and Reply 149. The base mounts all 300 messages (19,141 elements); this branch mounts 11 rows (1,856 elements) and publishes `aria-setsize="300"`.  At the top: both show Prompt 0 through Reply 1. The base still holds 300 rows (20,101 elements); this branch holds 19 (2,282 elements).  --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Han <[email protected]>
Opening panels and scrolling long chats can stall WebKitGTK because offscreen message content still participates in style and layout work. For Linux threads with 100+ messages, park completed offscreen bodies behind measured placeholders while retaining their React state. Restore rich content for scrolling, focus, find, selection, and print. Also reduce offscreen code highlighting and keep browser-panel constraints stable during opening and closing.
Prevent blank chat frames while history loads or the native scrollbar jumps. A transparent fixed-background sentinel synchronizes WebKitGTK overflow scrolling with main-thread painting. Commit small history batches and their anchor corrections in the same rendering frame, pause loading during scrolling, typing, composition, and pointer interaction, and hold message heights during thumb drags. Reuse the existing measurement-free collapsible for tool panels to avoid repeated forced layouts from closed disclosures.
Keep text stationary as history loads: preserve the compensated anchor between batches so intervening reflows are included, and absorb fractional inserted heights in a leading spacer under one pixel. WebKit can then apply whole-pixel scroll corrections without repeatedly moving the text between fractional positions.
Validation:
Full history still mounts progressively. Extremely fast drags through complex replies can drop frames; these checks establish that the reproduced periodic blanking and visible loading shake did not recur in the tested sequences.
Related to #16603. This complements #16656 and #16782; message windowing and the scrolling workaround are limited to WebKitGTK.