Repository navigation
Studio: stop the autoscroll follow flag restyling the whole thread in WebKit - #17035
Merged
Merged
Conversation
The autoscroll owner flips data-aui-following at the start and end of every follow window, which any width change of the chat column opens (run settings, browser pane, sidebar). The flag sat on the hidden portal host and index.css reached the viewport through it with `.aui-thread-host[data-aui-following] + .aui-thread-root .aui-thread-viewport`. WebKit invalidates every descendant of the host's later siblings for such a rule, so each flip restyled the whole thread: 31-261 ms (median 57-62) per flip at 150 turns against 1-4 ms at 1 turn. The flip lands inside the autoscroll tick, which then forces the restyle, so run settings and the sidebar paid it twice per toggle, once when opening the window and once in the settle tail 600 ms later. The flag now sits on the viewport and the rule matches it as the subject: `.aui-thread-viewport[data-aui-following]`. It is the same overflow-anchor: none on the same element for the same window, so scrolling behaves as before. A flip now costs 3-9 ms in WebKit and 0-1 ms in Chromium at 150 turns. The unused markerRef goes away.
Member
Author
|
@codex review |
Codex Review Summary: ✅ CompletedThis 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. |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On long chats in WebKit (macOS Safari / WKWebView), opening or closing Run settings costs 3-4x what it costs on a short chat (real
macos-15runners at 150 turns: longest frame 120-159 ms against 32-49 ms). The sidebar toggle grows the same way (120-245 ms against 35-46 ms).At 1440 px the sheet does not re-wrap anything: the message column is capped at 744 px and stays 744 px when the chat area narrows from 1160 to 888 px. Only 3 of 300 rows are in layout in WebKit (7 in Chromium) after #16986. The cost that grows with the chat comes from the autoscroll owner instead:
data-aui-followingon at the start and off in the settle tail about 600 ms later.index.cssreached the viewport through it:.aui-thread-host[data-aui-following] + .aui-thread-root .aui-thread-viewport. For a rule that reaches its subject through a sibling and then a descendant combinator, WebKit invalidates every descendant of the host's later siblings, which is the whole thread.scrollHeightright after, so the restyle is forced there: 40-70 ms per flip at 150 turns against 1-4 ms at 1 turn, twice per toggle (once in the opening frame, once in the settle tail).Chromium only restyles the viewport for the same rule (2.6 ms per flip at 150 turns), which is why Chromium and Edge were already close to flat.
Fix
use-intent-aware-autoscroll.tsx: the flag is set on the viewport itself (the element the hook already owns), through onesetFollowinghelper used by the tick, the idle frame and teardown.index.css: the rule matches the flag on its subject,.aui-thread-viewport[data-aui-following] { overflow-anchor: none; }. Same property, same element, same window as before, so scroll anchoring behaves as it did.thread.tsx: drops the now unusedmarkerReffrom the portal host.Results
Local, Playwright WebKit with a macOS user agent and Chromium, 1440x900, 1 and 150 turns (300 messages, 57k nodes). Arms interleaved per rep:
main, a second build ofmainserved by a separate server (A/A), and this PR. 5 runs x 3 toggles per cell, median [min-max].Cost of one flag flip (forced style + layout, 16 flips per cell, the element each build's hook writes):
Script time inside animation frames during a toggle (the autoscroll ticks, where the restyle is forced), WebKit:
Long / short ratio of that script time: Run settings 15.8-30.7x on
main(both builds), 3.2-3.4x with this PR.Chromium, style / layout thread time from a trace of one open + close at 150 turns: Run settings 28.0 / 5.8 ms (
main), 14.9 / 6.0 ms (A/A), 16.7 / 5.6 ms (this PR), against 13-15 / 2.5 ms at 1 turn. Browser pane 73 / 101, 51 / 77, 52 / 68 ms (about 45-51 / 46-50 ms at 1 turn). Elements restyled per toggle are the same in all arms (418-422 for Run settings). Chromium was already close to flat, and this PR keeps it there.Longest frame (ms, median [min-max]):
The longest-frame numbers do not separate the arms. This host ran at a load average of about 390 on 49 cores, the two
mainbuilds differ by up to 2x in the same cell, and Chromium traces show single style passes of 541 ms wall time for 9 ms of thread time. The table is here for completeness. The flip cost and the script time above are the measurements that hold up on this host.What else runs during a toggle at 150 turns (WebKit, after this PR):
distant-rows.tsanchor correction did not run.data-scrolls-xcheck and the thread width steps observer. Median 98-120 ms at 150 turns and 52-61 ms at 1 turn in all three arms; they are where the per-frame layout of the pane's 260 ms flex-basis transition gets forced. Run settings fires none of them.flex-basis. Turning that transition off locally did not make WebKit cheaper at 150 turns (longest frame with it off: open 684 ms, close 334 ms; with it on: 459 ms and 257 ms; within noise), so this PR leaves it alone.Behaviour
Main and this PR, WebKit (mac UA) and Chromium, 150 turns:
overflow-anchor: nonewhile following andautoafter the window closes, in both arms and both engines.main.mainand this PR, all 8 WebKit ones included. The other two (Chromium, pane closed) differ in a 1-2 px wide strip of glyph antialiasing at a line end.Tests
tests/thread-follow-flag-selector.test.ts(3 tests): the flag is matched on the viewport as the subject, the hook writes it on the viewport through one setter, and no thread rule reaches the viewport through an attribute on a sibling. All 3 fail onmain.npm test: 15160 passed, 1 failed. The failure is the KaTeX stylesheet Vite test, which also fails onmainwith a symlinkednode_modules.node scripts/typecheck.mjs --tests: clean.tests/studio/playwright_long_thread_gate.py): PASS. Itsrun_settingsarea restyles 571 -> 1,217 elements from 40 to 200 turns, the same as other trees from today (567-577 -> 1,209-1,216).tests/studio/test_autoscroll_harness_contract.py: 16 passed.tests/studio/playwright_chat_autoscroll.pyfails the same way onmainand on this PR on this host ("the content did not grow while detached; the re-pin check proved nothing").Not covered
macos-15runners would settle it.message-window-controller.ts.Real macOS runner check
macos-15, current main vs a second build of the same main (A/A) vs this PR merged onto main, 150 turns, 4 reps in balanced order, all built == served.