Repository navigation
Studio: open Settings and the shortcuts list with one panel render and one focus move - #17042
Merged
Merged
Conversation
…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.
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. 🚀 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
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:
useDeferredValueliving 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.requestAnimationFramemoved 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.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.useScrollFades), which re-rendered the whole dialog, including the active panel, right after mount.The rest of the open, mostly at 150 turns, is outside the dialog:
RootLayoutre-renders on the Settingsopenflag (document title and theenabledflag 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), andChatPageeffects run again. TakingRootLayoutoff 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.tsxSettingsPanelPanethat mounts with the dialog's content. On mount,useDeferredValuereturns 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.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.onOpenAutoFocusfocuses 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. TherequestAnimationFramefocus now runs only when focus is not already on the active tab, for example after a search result changes the tab.0px, the CSS fallback.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]).hsyncis a variant tried and rejected: it renders the prefetched panel in the same pass as the dialog on the first open.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).hsyncshows 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)
Reading:
Raw:
outputs/settings_open/first/,outputs/settings_open/cpu_c1/(per-cycle JSON). Tables viascripts/settings_open/first_summary.pyandbody_tables.py.Behaviour
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.tests/studio/playwright_settings_tabs.pypasses in Chromium and WebKit.Tests
tests/settings-tab-panel-loading.test.tsis 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 teston 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
ChatPageeffects that re-run on open were not investigated.studio_regresssettings journey was not run (it needs a PR).