Repository navigation
perf(browser-pane): stop the client-hosted page position loop when nothing changes - #37188
Conversation
|
No actionable comments were generated in the recent review.
|
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
ae96af42-7333-4386-93ec-7825e88b205b
Files selected for processing: 2-
src/renderer/src/components/browser-pane/browser-client-page-position-driver.test.tssrc/renderer/src/components/browser-pane/browser-client-page-position-driver.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
-
…thing changes The shared position driver requested an animation frame every frame for as long as any client-hosted page or docked DevTools was shown, keeping the renderer and compositor at display refresh rate while the app sat idle. Frames now run only in a short settle window after something that can move a pane or open an overlay: DOM mutations, viewport resize/scroll/DPR changes, transitions and animations, input/focus/drag events, font and resource loads. Finite running animations extend the window; endless spinners do not. The DevTools dock also resyncs directly on drag passthrough changes.
…rminal/editor DOM churn Busy-case measurement showed the 250 ms settle window kept syncs at 60/s under any steady DOM traffic (sidebar rows re-rendering every 200 ms, xterm scrollbar style writes while output streams). Every DOM change already wakes the driver, so two frames per wake are enough; mutations confined to .xterm/.monaco-editor can't move panes and no longer wake it.
8464f58 to
767f839
Compare
… without frames A pane move with no DOM mutation, event or CSS animation (a style sheet edit, a script-driven animation) left the overlay stale until the next wake. A frameless 1 s recheck bounds that; unchanged rects write nothing, so an idle app still requests no frames.
ELI5
When a remote-workspace browser page (or docked DevTools) was on screen, Orca re-checked where that page should sit on every single display frame, 60 times a second, even when nothing on screen was moving. That kept the app's renderer and GPU busy while idle. Now it only re-checks for a moment after something actually changes.
What Changed
browser-client-page-position-driver.tsused to run an unboundedrequestAnimationFrameloop while any client-hosted page overlay or docked DevTools view was registered. The loop was there because a pane can move without firing a resize or scroll event (split drag, sidebar collapse, floating panel drag, overlays opening over the dock).The driver is now wake-driven:
MutationObserver(child list, attributes, character data), windowresize/scroll(capture), transition/animation start/end/cancel, pointer/key/focus/drag events (covers:hover/:focusstyle changes),load(capture), font loading,visibilitychange, and device-pixel-ratio changes..xterm/.monaco-editordon't wake it. These fixed-size widgets rewrite their own DOM all the time (the xterm scrollbar slider gets a style write on every output chunk) and can't move a pane.requestAnimationFrame). Unchanged rects write nothing, so idle still requests no frames. If a move had no wake (a style sheet edit, a script-driven animation), the overlay is corrected within 1 s instead of staying wrong until the next interaction. The corrected host's style write then starts a normal burst.registerWebviewDragPassthroughSurface), so it doesn't depend on a wake.Why
A perpetual rAF loop is the same idle-CPU problem as the agent-spinner compositor issue: the compositor produces BeginImplFrames at refresh rate and the main thread forces a layout read every frame, even when the rect hasn't changed. With this change, pane moves still get tracked because every layout change starts with a DOM/style/viewport/input change, and that change wakes the driver.
A per-element
IntersectionObserverlayout-shift trick could catch pure moves of the host container. It can't see overlays opening over the DevTools dock, though, and the dock needs that. Watching for mutations and events covers both consumers with one mechanism.Wake-source audit
What the driver actually affects: only the
left/top/width/heightof a client-hosted page's body-level host div, and the DevTools dock's native view bounds. Host size is also kept in sync by the host's ownResizeObserverand windowresizelistener, independent of the driver. So for client-hosted pages, a missed wake can only leave a pure move stale. The dock relies on the driver for everything.resize(+ host's own resize listener +ResizeObserver)afterWindowResize: host == container, dock view == placeholderresize+(resolution: Ndppx)media querydevicePixelRatioafterSidebarToggle(host and dock)wakes on a DOM change that moves a paneafterCliCreate,whileWorkspaceInBackground,afterReturnFromBackgroundhasVisibleOverlayOverruns in the same sync)registerWebviewDragPassthroughSurfaceresyncscroll(capture)transitionrun/animationstart+ mutation that applied them; finite ones followed viagetAnimations()loadingdone,load(capture)visibilitychangeadoptedStyleSheetsedits, Web Animations started without a DOM change, mutations in shadow roots, layout shifts originating inside.xterm/.monaco-editorelement.animatecalls only move sidebar rows, the load-progress bar and the agent cursor)CLI browser automation verification (main vs this PR)
CLI browser commands go main process → guest
webContentsover CDP (Input.dispatchMouseEvent,Page.captureScreenshot,capturePage, accessibility snapshot). Coordinates are guest-viewport CSS px, so the host div's window position never enters the path. The guest viewport size follows the host's size, whichResizeObserverkeeps in sync without the driver. Local browser panes and server-placed remote pages don't use this driver at all.End-to-end check: an ad-hoc spec, not checked in. It uses a headless paired runtime host plus a paired Electron client, both launched with
ORCA_BACKGROUND_LAUNCH=1, and runs the real compiledorcaCLI against the host. The same spec ran on three builds: based337a1efed3, the previous PR revision767f8395424, and this revision. Each phase runssnapshot,click --element @ref,fill --element @ref,mouse move/down/upat (180,150),eval, andscreenshot.tab createfrom the server CLI (agent, no user input). That page is server-placed; commands on itsetBounds, no show/focus)adoptedStyleSheetstranslate, overlay aligned at 100/600/1500/3000 ms"pass" in every phase means all of these held: both clicks landed on
#btnat (180,150); the filled value read back; the screenshot size equalled the guest viewport and the container size; the host rect equalled the container rect; and there were no errors.Existing e2e on this revision, all passing (19 tests):
paired-client-hosted-browser,paired-client-hosted-browser-markup,paired-client-hosted-browser-host-strip,paired-split-pane-browser-placement,browser-pointer-input-dispatch,browser-agent-input-focus-isolation,browser-tab.Idle cost, client-hosted page shown (same spec, paired client renderer, 10 s, after closing the server-placed tab)
Linked Issue
N/A (maintainer perf follow-up; same class as #14882)
Visual Proof
N/A: there's no visual change. Overlays should land in the same place as before. The live check below confirms that.
Measurements
macOS, dev build launched with
ORCA_BACKGROUND_LAUNCH=1, idle window (rAF confirmed at 60 Hz while hidden-launched). Each run is a 10 s window. A sync was registered through the real driver module, using the same body as the visible-attachment sync ("host") or the DevTools-dock sync ("dock"). Renderer/GPU CPU come fromSystemInfo.getProcessInfodeltas, task time fromPerformance.getMetricsTaskDuration, and frames fromScheduler::BeginImplFrameon the renderer Compositor thread.Live correctness check on the patched driver, using a registered sync tracking a fixed element:
Busy case (same method, 8 folder workspaces, renderer at full load)
Each row is a 10 s window, two runs per variant (A / B).
noneis no host registered. Spinner scenarios already run the compositor at 60 fps from CSS spinners, so BeginImplFrame can't tell the variants apart there; sync runs/s is the direct signal. The workload itself is noisy (±20–40 ms/s between runs), so compare each row with its ownnonerow.agents: the e2e spinner fixture's traffic,setAgentStatuson 8 working agents every 200 ms. It produced ~0 DOM mutations per second.agentsToggle: the same traffic, but flipping working/waiting each tick, so sidebar rows really re-render.terminal: a 60-char line printed every 20 ms in the active pane.Results:
agentsToggleandterminalit still ran 60 syncs/s, the same as before, so this revision narrows both.Live correctness check (re-run on this revision):
leftchange (no resize)200pxwithin 100 ms)transformtransition (longer than the settle window)300px)Testing
browser-client-page-position-driver.test.tsnow covers going idle after the settle frames, waking on a DOM change that moves a pane, staying idle while a terminal rewrites its own DOM, continuing through a finite animation and not through an endless one, healing a no-wake move on the next recheck with no frames while unchanged, plus the existing shared-frame, error-isolation, hidden-document and release cases.Ran:
pnpm test src/renderer/src/components/browser-pane --maxWorkers=2(115 files, 976 tests pass),pnpm tc,oxlint/oxfmt --checkon the changed files, andpnpm check:code-quality:changed origin/main.Risk
A pane move with no DOM mutation, viewport/style event, or CSS animation is now stale for at most ~1 s; before this revision it stayed stale until the next interaction. The audit above lists the remaining no-wake classes. No current code path was found that triggers them.
CLI browser automation does not depend on the driver. Input and screenshots are guest-relative over CDP, and the guest size is maintained by
ResizeObserver. All CLI phases above behave identically on base and this PR.UIs that mutate the DOM continuously outside terminals and editors still wake the driver on each mutation batch. The busy-case table shows that stays at or below the old cost. The
.xterm/.monaco-editorfilter assumes those widgets don't move panes from internal DOM changes. If one did, the recheck bounds it at 1 s.Untested: Linux and Windows (code is platform-neutral Chromium events, but only macOS was run). SSH/orcad remote topologies (paired-runtime topology was tested). A real high-DPI monitor switch.
No saved data, IPC, or mixed-version surfaces are touched. It's renderer-only. To back it out, revert these commits.
Level: Low
Agent skill upstream boundary
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (typecheck + scoped tests + changed-file lint run locally; CI covers the rest)