Skip to content

Studio: open Settings and the shortcuts list with one panel render and one focus move - #17042

Merged
danielhanchen merged 3 commits into
mainfrom
studio-settings-open-fast
Nov 9, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-settings-open-fast

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

Opening Settings (Mod+Comma) or the keyboard shortcuts list (Mod+/, the same dialog on its Shortcuts tab) costs about 420 ms solid and 600 ms Glass on macOS WebKit with a 150-turn chat, and 250-480 ms with a 1-turn chat. Most of that is the open itself, not the chat. Local attribution (Chromium CPU profile + trace with the React profiling build, and Playwright WebKit with a Mac UA plus timing of every layout-forcing call) found these costs inside the dialog:

  • Opening on a different tab rendered the wrong panel first. The panel tab was a useDeferredValue living in the always-mounted dialog. Opening the shortcuts list after General rendered the full General panel in the open's frame, then the Shortcuts panel in a second pass. The same applies to every deep link that opens another tab.
  • Two focus moves per open. Radix focused the search box, then a requestAnimationFrame moved focus to the active tab. In WebKit each focus move forces a style and layout pass over the page: 74-537 ms each per open at 150 turns on this host.
  • Forced layouts mid-commit. The tab rail read its own scroll bar width (offsetWidth - clientWidth) from a ref callback during commit: 18-156 ms in WebKit. The ResizeObserver next to it already reports the same value once layout is done. Opening on another tab also ran the scroll reset on a freshly mounted scroller: 125-243 ms.
  • Panel re-rendered by the dialog's own updates. The rail's ref callback sets state (useScrollFades), which re-rendered the whole dialog, including the active panel, right after mount.
  • Panel prefetch on every open. Every open queued all 18 tab imports on idle (15-100 ms per open). The first open also had no prefetched panel, so it waited on the chunk behind a Suspense boundary.

The rest of the open, mostly at 150 turns, is outside the dialog: RootLayout re-renders on the Settings open flag (document title and the enabled flag of the route shortcuts), shortcut availability checks query the DOM (about 110 ms per open at 150 turns in the Chromium profile before #17005, now merged), and ChatPage effects run again. Taking RootLayout off the open flag was measured and gave nothing once #17005 landed, so it is not included.

Fix

First commit, all in studio/frontend/src/features/settings/settings-dialog.tsx

  • The panel (deferred tab, scroll reset, search-hit scrolling, Suspense and error boundary) moves into a memoised SettingsPanelPane that mounts with the dialog's content. On mount, useDeferredValue returns the requested tab, so an open renders the right panel once. Tab switches while the dialog is open are deferred as before. The dialog's own re-renders skip the pane.
  • A tab's first view in the page paints the dialog first and renders the panel in a background pass right after (useDeferredValue(tab, null)). Before this change, the first open showed the dialog first and the panel later while its chunk loaded. Once a panel has been shown, later opens render it in the same pass, as before.
  • Prefetch: after startup (3 s, then idle) the tab Settings opens on and the shortcuts list. After an open, the remaining panels load once per page, one per idle slot, instead of all 18 on every open. A failed prefetch is not cached, so the panel's own load tries again (the old behaviour).
  • onOpenAutoFocus focuses the active tab directly and prevents Radix's default. That is one focus move instead of two. If the tab cannot take focus, Radix's default still runs. The requestAnimationFrame focus now runs only when focus is not already on the active tab, for example after a search result changes the tab.
  • The rail's scroll bar width comes only from its ResizeObserver, which also fires once on observe. An unset value counts as 0px, the CSS fallback.
  • The scroll reset skips the panel's mount, because the scroller is new and already at the top.

The final rendered dialog is unchanged. One difference shows during the open: opening on another tab no longer shows the previous tab's panel for a frame.

Results

Local Linux host. Other users kept the load average at 200-600 throughout, so absolute ms are inflated. Base is origin/main 997441a, which includes #17005. A/A is a second build of the same commit on its own server. Head is this branch. The arms run at the same time against one real Studio backend each, with the arm order rotated, and each run uses its own browser.

The CPU rows are the CPU time of the whole browser process tree from the trigger until the DOM has been quiet for 500 ms, minus that page's idle CPU rate over the same window. Host load affects this metric much less than wall time. "Visible" (input to the frame after the dialog is visible) and "max frame" are menu_bench's wall-clock metrics. On this host their A/A ratios span 0.6-1.9, so only a head ratio clearly outside its row's A/A counts as a result. Each cell is base -> head, then (head/base; A/A/base).

First open after a fresh page load

6 fresh page loads per arm and cell, one Settings open each. "Panel" is the time from the input to the panel being committed ([data-settings-panel-ready]). hsync is a variant tried and rejected: it renders the prefetched panel in the same pass as the dialog on the first open.

engine turns metric n base aa head hsync aa/base head/base hsync/base
webkit_mac 1 vis 6/6/6/6 420 [301-531] 418 [382-461] 372 [296-438] 651 [593-752] 1.00 0.89 1.55
webkit_mac 1 max 6/6/6/6 306 [210-355] 287 [236-320] 274 [198-310] 490 [440-566] 0.94 0.90 1.60
webkit_mac 1 panel 6/6/6/6 658 [460-764] 693 [666-766] 460 [346-610] 443 [389-500] 1.05 0.70 0.67
webkit_mac 1 cpu 6/6/6/6 1443 [1379-1527] 1477 [1360-1706] 1486 [1348-1718] 1555 [1396-1611] 1.02 1.03 1.08
webkit_mac 150 vis 6/6/6/6 1343 [1197-1486] 1332 [1164-1420] 1167 [1041-1329] 1526 [1378-1878] 0.99 0.87 1.14
webkit_mac 150 max 6/6/6/6 533 [506-609] 525 [478-620] 508 [470-599] 730 [651-769] 0.98 0.95 1.37
webkit_mac 150 panel 6/6/6/6 1556 [1358-1798] 1646 [1350-1830] 1288 [1184-1494] 1256 [1156-1293] 1.06 0.83 0.81
webkit_mac 150 cpu 6/6/6/6 2037 [1809-2576] 2290 [1850-2582] 2690 [2376-3041] 2608 [1959-2832] 1.12 1.32 1.28
chromium 1 vis 6/6/5/5 171 [153-318] 173 [113-210] 161 [139-254] 345 [225-404] 1.01 0.95 2.02
chromium 1 max 6/6/5/5 158 [150-300] 158 [100-200] 150 [133-250] 333 [217-400] 1.00 0.95 2.11
chromium 1 panel 6/6/5/5 454 [417-650] 430 [395-459] 325 [263-405] 265 [167-321] 0.95 0.72 0.58
chromium 1 cpu 6/6/5/5 1018 [957-1277] 898 [858-1127] 896 [768-1065] 920 [816-1040] 0.88 0.88 0.90
chromium 150 vis 5/6/6/6 225 [163-371] 244 [223-291] 183 [160-210] 333 [301-355] 1.08 0.81 1.48
chromium 150 max 5/6/6/6 200 [167-367] 233 [217-283] 167 [150-200] 325 [283-350] 1.17 0.83 1.63
chromium 150 panel 5/6/6/6 499 [415-769] 470 [419-583] 296 [254-349] 235 [194-266] 0.94 0.59 0.47
chromium 150 cpu 5/6/6/6 1246 [978-2024] 1186 [1122-1394] 1083 [988-2173] 952 [839-1075] 0.95 0.87 0.76

Head paints the dialog no later than main in every cell (visible 0.81-0.95x, max frame 0.83-0.95x; A/A 0.94-1.17). The panel is ready 0.59-0.83x sooner (A/A 0.94-1.06), because it is prefetched and no longer waits for its chunk. Rendering the panel in the same pass (hsync) makes the first frame 1.14-2.02x later, so first views stay deferred. One cell sits above its A/A: WebKit at 150 turns, CPU 1.32x (A/A 1.12; ranges 2376-3041 against 1809-2576 ms). hsync shows the same (1.28x). The extra CPU falls after the first frame: visible and max frame are lower in that cell.

Warm opens and closes (cycles 2-6 of 6), and the first cycle of each surface

Solid (3 interleaved reps per arm)

WebKit (mac UA), 1 turn WebKit (mac UA), 150 turns Chromium, 1 turn Chromium, 150 turns
Settings open, CPU ms 995 -> 830 (0.83; A/A 0.90) 1478 -> 1352 (0.91; A/A 1.00) 500 -> 444 (0.89; A/A 0.85) 522 -> 474 (0.91; A/A 1.12)
Settings open, visible ms 441 -> 487 (1.10; A/A 1.02) 1099 -> 948 (0.86; A/A 0.92) 225 -> 247 (1.10; A/A 0.94) 265 -> 242 (0.91; A/A 0.93)
Settings open, max frame ms 353 -> 418 (1.18; A/A 1.01) 678 -> 616 (0.91; A/A 0.87) 217 -> 233 (1.08; A/A 0.92) 250 -> 233 (0.93; A/A 0.93)
Settings close, CPU ms 500 -> 511 (1.02; A/A 1.07) 821 -> 810 (0.99; A/A 1.00) 312 -> 301 (0.96; A/A 0.86) 400 -> 413 (1.03; A/A 0.99)
Settings close, visible ms 353 -> 337 (0.95; A/A 0.91) 557 -> 565 (1.01; A/A 1.21) 209 -> 193 (0.92; A/A 0.86) 219 -> 245 (1.11; A/A 1.04)
Settings close, max frame ms 125 -> 109 (0.87; A/A 1.00) 264 -> 280 (1.06; A/A 0.81) 83 -> 67 (0.80; A/A 1.20) 100 -> 83 (0.83; A/A 0.83)
Shortcuts open, CPU ms 637 -> 578 (0.91; A/A 0.96) 867 -> 821 (0.95; A/A 0.99) 317 -> 263 (0.83; A/A 1.12) 389 -> 364 (0.94; A/A 1.07)
Shortcuts open, visible ms 391 -> 335 (0.86; A/A 0.97) 626 -> 489 (0.78; A/A 1.09) 213 -> 162 (0.76; A/A 0.92) 225 -> 198 (0.88; A/A 0.90)
Shortcuts open, max frame ms 318 -> 288 (0.91; A/A 0.97) 441 -> 423 (0.96; A/A 1.08) 200 -> 150 (0.75; A/A 0.92) 217 -> 183 (0.85; A/A 0.92)
Shortcuts close, CPU ms 459 -> 437 (0.95; A/A 1.04) 769 -> 660 (0.86; A/A 0.91) 277 -> 272 (0.98; A/A 1.06) 413 -> 366 (0.89; A/A 0.96)
Shortcuts close, visible ms 299 -> 330 (1.10; A/A 1.16) 493 -> 431 (0.87; A/A 0.97) 197 -> 206 (1.05; A/A 0.95) 241 -> 214 (0.89; A/A 0.96)
Shortcuts close, max frame ms 114 -> 111 (0.97; A/A 1.52) 248 -> 235 (0.95; A/A 1.00) 83 -> 67 (0.80; A/A 1.00) 100 -> 67 (0.67; A/A 1.17)
First Settings open of the page, CPU ms 1421 -> 1400 (0.99; A/A 0.89) 2185 -> 2168 (0.99; A/A 0.99) 1003 -> 1013 (1.01; A/A 0.96) 1750 -> 1140 (0.65; A/A 0.58)
First Settings open of the page, visible ms 453 -> 489 (1.08; A/A 1.28) 1182 -> 992 (0.84; A/A 0.93) 157 -> 149 (0.95; A/A 1.03) 207 -> 243 (1.17; A/A 1.10)
First Settings open of the page, max frame ms 297 -> 271 (0.91; A/A 1.04) 559 -> 594 (1.06; A/A 1.02) 150 -> 150 (1.00; A/A 1.00) 200 -> 233 (1.17; A/A 1.08)
Shortcuts opened from General (tab change), CPU ms 847 -> 519 (0.61; A/A 1.27) 1190 -> 747 (0.63; A/A 1.12) 685 -> 351 (0.51; A/A 0.82) 683 -> 330 (0.48; A/A 1.13)
Shortcuts opened from General (tab change), visible ms 396 -> 214 (0.54; A/A 1.16) 679 -> 371 (0.55; A/A 1.13) 160 -> 160 (1.01; A/A 1.31) 224 -> 131 (0.58; A/A 1.08)
Shortcuts opened from General (tab change), max frame ms 330 -> 180 (0.55; A/A 1.18) 453 -> 322 (0.71; A/A 1.19) 150 -> 149 (0.99; A/A 1.33) 217 -> 117 (0.54; A/A 0.97)

Reading:

  • Opening on another tab (the shortcuts list from General, or any deep link): CPU 0.48-0.63x (A/A 0.82-1.27). Visible 0.54-0.58x in WebKit at 1 and 150 turns and in Chromium at 150 turns.
  • Warm opens: Settings CPU 0.83-0.91x, shortcuts 0.83-0.95x (A/A 0.85-1.12).
  • WebKit layout-forcing calls per open (separate probe, 150 turns, before the rebase, ms forced per open over 3 opens): Settings 418 / 854 / 409 -> 294 / 407 / 341; shortcuts 1180 / 518 / 799 -> 149 / 226 / 336. The one remaining focus move (143-255 ms) accounts for most of what is left.
  • Closes: within noise.

Raw: outputs/settings_open/first/, outputs/settings_open/cpu_c1/ (per-cycle JSON). Tables via scripts/settings_open/first_summary.py and body_tables.py.

Behaviour

  • Every Settings tab is screenshotted on base, A/A and head, in Chromium and WebKit with a Mac UA, 1-turn chat (18 tabs). 0 changed pixels except areas that differ between A/A too: the per-server home path shown in Chat / Agents / API / Library, live RAM and CPU on Resources, log lines on Logs, and rows that appear once an API answers (Data: the two import-from-tool rows; Library: Exports). With an 8 s wait, Data, Library and General are 0 px for both aa and head. The settings labels and element counts per tab are identical.
  • Settings search: the results for 10 queries (theme, shortcut, token, cache, voice, model, api, sandbox, language, zzzz) are identical in both engines. A hit on a row in a tab that is not mounted opens that tab and scrolls the row into view, in both arms.
  • Focus: after an open it is on the active tab (Mod+Comma, the sidebar button, and Mod+/ straight from closed). Tab moves on to the next tab. After close it returns to the composer or the Settings button, as on base, for opens by key, by click, after a tab switch and after a search jump.
  • Deep opens from outside (voice, API keys, data, about, connections), an abandoned deep open, scroll reset between tabs, chunk-delay and chunk-failure handling: tests/studio/playwright_settings_tabs.py passes in Chromium and WebKit.
  • Focus return after close on the final head, in Chromium and WebKit, matches base in all 7 sequences: key, tab switch, search jump, from body, and click.

Tests

  • tests/settings-tab-panel-loading.test.ts is updated for the new prefetch and adds checks that the deferred tab lives in the pane, the open focus, and that the rail does not read layout mid-commit.
  • npm test on the final head: 15198 pass, 1 fail. The failure is the known KaTeX stylesheet Vite test with symlinked node_modules.
  • node scripts/typecheck.mjs --tests: exit 0.
  • tests/studio/playwright_settings_tabs.py (Chromium, WebKit): pass. tests/studio/playwright_keyboard_shortcuts.py: 232/232.
  • tests/studio/playwright_long_thread_gate.py: PASS.

Not covered

  • No real macOS run: WebKit here is Playwright WebKit (WebKitGTK) with a Mac UA and platform, not Safari or the Desktop app's WKWebView. There was no Edge / WebView2 or Windows run either.
  • Wall-clock visible and max frame ratios on this host are noisy (A/A 0.6-1.9). The CPU metric is steadier but still has A/A 0.8-1.3 on single first-open cycles.
  • The Glass backdrop cost was not attributed separately. Glass costs more in every arm, and this PR does not change it.
  • The tab screenshots and the search checks ran on the first commit before the rebase onto 997441a, with the same code. The first-open probe is solid only, no Glass.
  • Desktop (Tauri) app menu greying under Settings is checked by source test only. No desktop shell was run.
  • ChatPage effects that re-run on open were not investigated.
  • The studio_regress settings journey was not run (it needs a PR).

…d one focus move

- Mount the deferred panel with the dialog's content, so an open renders the requested tab
  instead of the last one first (opening shortcuts from General rendered General, then Shortcuts).
- A tab's first view in the page paints the dialog first and renders the panel right after;
  later opens render it in the same pass. Prefetch the tab Settings opens on and the shortcuts
  list after startup, and the rest once per page, one per idle slot, instead of on every open.
- Focus the active tab in onOpenAutoFocus instead of the search box first and the tab a frame
  later: each focus move restyles the page in WebKit.
- Drop the rail's scroll bar read mid-commit (the ResizeObserver already reports it) and the
  scroll reset on a freshly mounted panel, both forced layouts.
- Memoise the panel, so the dialog's own re-renders on open skip it.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T16:53:28.642831Z 71f7320 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 71f7320bbe

ℹ️ 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".

@danielhanchen
danielhanchen merged commit c2a5595 into main Nov 9, 2026
@danielhanchen
danielhanchen deleted the studio-settings-open-fast branch November 9, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant