Skip to content

perf(browser-pane): stop the client-hosted page position loop when nothing changes - #37188

Merged
nwparker merged 3 commits into
mainfrom
nwparker/browser-pane-position-loop-idle
Nov 2, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/browser-pane-position-loop-idle

Conversation

@nwparker

@nwparker nwparker commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​96 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​93
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​149 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​131

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.ts used to run an unbounded requestAnimationFrame loop 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:

  • While at least one host is registered, it listens for anything that can move a pane or open an overlay: a document-wide MutationObserver (child list, attributes, character data), window resize/scroll (capture), transition/animation start/end/cancel, pointer/key/focus/drag events (covers :hover/:focus style changes), load (capture), font loading, visibilitychange, and device-pixel-ratio changes.
  • Each wake syncs every registered host on the next 2 frames. Every DOM change wakes the driver again, so a longer tail would only add work.
  • DOM changes confined to .xterm / .monaco-editor don'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.
  • If a finite CSS transition/animation is still running when the settle frames run out, frames continue until it finishes. Infinite animations (spinners) are ignored, so they do not keep it running.
  • When nothing changes, no frames get scheduled.
  • A frameless 1 s recheck reads each host's rect directly (no 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.
  • Per-host error isolation and release-on-last-unregister are unchanged.
  • The DevTools dock also resyncs directly when webview drag passthrough toggles (via the existing 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 IntersectionObserver layout-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/height of 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 own ResizeObserver and window resize listener, 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.

Way the pane bounds change Wake Evidence
Window resize, maximize, fullscreen, snap (all platforms) window resize (+ host's own resize listener + ResizeObserver) e2e afterWindowResize: host == container, dock view == placeholder
UI zoom / DPI change / move to a monitor with a different scale resize + (resolution: Ndppx) media query code; dock sync also keys on devicePixelRatio
Sidebar toggle / sidebar drag React commit, so a style/class mutation; pointer events e2e afterSidebarToggle (host and dock)
Split divider drag, floating panel drag, textarea resize style mutation + pointer events code; unit test wakes on a DOM change that moves a pane
Tab / worktree switch, pane created or shown programmatically (CLI, agent) childList/attribute mutation e2e afterCliCreate, whileWorkspaceInBackground, afterReturnFromBackground
Overlays (dialog, menu, popover, toast) opening or closing over the dock childList mutation (portals) code (hasVisibleOverlayOver runs in the same sync)
Dock drag passthrough toggle direct registerWebviewDragPassthroughSurface resync code
Ancestor scroll scroll (capture) code
CSS transitions/animations, incl. with delay transitionrun/animationstart + mutation that applied them; finite ones followed via getAnimations() unit test
Hover/focus style changes pointer/focus events code
Fonts/images loading loadingdone, load (capture) code
Background tab returning visibilitychange code
No-wake moves: CSSOM / adoptedStyleSheets edits, Web Animations started without a DOM change, mutations in shadow roots, layout shifts originating inside .xterm/.monaco-editor none e2e probes below: stale for 3 s+ on the previous revision; now healed by the 1 s recheck. Grep found no current renderer code that moves a pane this way (the existing element.animate calls 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 webContents over 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, which ResizeObserver keeps 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 compiled orca CLI against the host. The same spec ran on three builds: base d337a1efed3, the previous PR revision 767f8395424, and this revision. Each phase runs snapshot, click --element @ref, fill --element @ref, mouse move/down/up at (180,150), eval, and screenshot.

Phase base PR rev 1 this rev
tab create from the server CLI (agent, no user input). That page is server-placed; commands on it pass pass pass
Client-hosted page right after creation pass pass pass
After window resize (setBounds, no show/focus) pass pass pass
After sidebar toggle / toggle back pass pass pass
While its workspace is in the background (client switched to a folder workspace) pass pass pass
After returning from background pass pass pass
With DevTools docked (dock view bounds == placeholder after resize and sidebar toggle) pass pass pass
No-wake move probe: adoptedStyleSheets translate, overlay aligned at 100/600/1500/3000 ms ✓✓✓✓ ✗✗✗✗ ✓✓✓✓
No-wake move probe: Web Animation translate (300 ms) ✓✓✓✓ ✗✗✗✗ ✗✓✓✓

"pass" in every phase means all of these held: both clicks landed on #btn at (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)

Build rAF calls/s getBoundingClientRect/s TaskDuration ms/s Renderer CPU ms/s GPU CPU ms/s
base 60 60 18.6 19.7 7.6
PR rev 1 0 0 0.05 0.17 0.15
this rev 0 1 0.09 0.19 0.08

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 from SystemInfo.getProcessInfo deltas, task time from Performance.getMetrics TaskDuration, and frames from Scheduler::BeginImplFrame on the renderer Compositor thread.

Scenario Renderer CPU (ms/s) Renderer TaskDuration (ms/s) GPU CPU (ms/s) Compositor BeginImplFrame/s
No host registered (baseline) 0.3–0.5 0.07–0.17 0.2–0.4 0
Before: 1 client-hosted page shown 15.9–16.5 7.6–9.0 5.7–5.9 60
Before: docked DevTools shown 21.4 12.5–12.7 6.0–6.3 60
After: 1 client-hosted page shown 0.35–0.47 0.08–0.11 0.2–0.3 0
After: docked DevTools shown 0.36–0.43 0.08–0.14 0.3 0

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). none is 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 own none row.

  • agents: the e2e spinner fixture's traffic, setAgentStatus on 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.
Scenario Mode Variant Renderer CPU ms/s (A / B) TaskDuration ms/s GPU CPU ms/s BeginImplFrame/s Mutation callbacks/s Sync runs/s
idle (no agents) host before 32 / 21 23 / 11 9.8 / 6.4 60 0 60
idle (no agents) host after 0.5 / 0.6 0.2 / 0.1 0.4 / 0.5 0 0 0
idle (no agents) dock before 47 / 28 40 / 18 9.6 / 6.2 60 0 60
idle (no agents) dock after 0.8 / 0.5 0.3 / 0.1 0.3 0 0 0
agents none before / after 133, 106 / 105, 77 81, 74 / 72, 51 ~13–18 60 0 0
agents host before 140 / 142 113 / 121 18 60 0 60
agents host after 123 / 106 83 / 80 17–20 60 0 0–0.5
agents dock before 141 / 113 126 / 92 16–20 60 0.3 60
agents dock after 105 / 93 82 / 70 19–20 60 0.3 0.7
agentsToggle none before / after 190, 178 / 200, 161 136, 144 / 147, 128 42–46 40 10 0
agentsToggle host before 204 / 184 154 / 150 46 60 10 60
agentsToggle host after 186 / 162 136 / 133 43 42 10 16
agentsToggle dock before 199 / 203 164 / 147 44–45 60 10 60
agentsToggle dock after 178 / 179 146 / 147 44 42 10 16
terminal none before / after 106, 72 / 111, 117 82, 44 / 84, 81 69–102 60 6 0
terminal host before 100 / 70 83 / 42 68–88 60 6 60
terminal host after 115 / 118 81 / 87 102–104 60 6 0–5
terminal dock before 111 / 79 88 / 51 71–87 60 6 60
terminal dock after 113 / 110 83 / 87 96–101 60 6 0.5

Results:

  • After is not worse than before in any scenario. Sync runs drop from 60/s to 0–16/s.
  • The first revision used a 250 ms settle window and no terminal/editor filter. Under agentsToggle and terminal it still ran 60 syncs/s, the same as before, so this revision narrows both.
  • Under heavy load, the CPU difference is mostly inside the run-to-run noise. The terminal workload's baseline swung between runs (72 vs 117 ms/s with no host), and the GPU cost there comes from the terminal rendering, not this driver.
  • The clear win is idle, plus agent traffic that doesn't touch the DOM: the dock/host sync cost of ~10–45 ms/s TaskDuration goes away.

Live correctness check (re-run on this revision):

Check Result
Sync calls per second while idle 0
Pure move via inline left change (no resize) tracked (200px within 100 ms)
600 ms transform transition (longer than the settle window) tracked mid-flight and to the final position (300px)
Sync calls in the second after the transition ends 0

Testing

  • I manually tested these changes locally (CDP measurements and live check above, macOS)
  • Automated tests added/updated: browser-client-page-position-driver.test.ts now 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 --check on the changed files, and pnpm 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-editor filter 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (typecheck + scoped tests + changed-file lint run locally; CI covers the rest)

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent 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: e759c18a-1795-41ec-91fd-8fe1164dbc86
Commits

Reviewing files that changed from the base of the PR and between 767f839 and f76dda5.

Files selected for processing: 2
  • src/renderer/src/components/browser-pane/browser-client-page-position-driver.test.ts
  • src/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.

Walkthrough

The shared browser-page position driver now schedules frame bursts in response to wake sources. It continues scheduling during the settle interval or while a finite animation runs, then stops. Releasing the last host removes the shared wake sources. The DevTools dock hook registers its sync callback as a drag-passthrough surface. Tests cover settling, mutation-triggered scheduling, periodic rechecks, finite and infinite animations, and recovery after a host error.

Merge Risk: Minimal · up to f76dd

The wake-driven synchronization change has no identified merge-blocking issue.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: replacing the continuously running page-position loop when no changes occur.
Description check Passed The description is complete and relevant. It covers the user impact, implementation, rationale, testing, measurements, risks, platform limitations, visual proof, and rollback plan. It also explains wh…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is complete and relevant. It covers the user impact, implementation, rationale, testing, measurements, risks, platform limitations, visual proof, and rollback plan. It also explains why the full local lint, typecheck, test, and build commands were not all run.

Full details: Docstring Coverage

Explanation

Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 10 functions across 4 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Commits

Reviewing files that changed from the base of the PR and between 29217e4 and 8464f58.

Files selected for processing: 2
  • src/renderer/src/components/browser-pane/browser-client-page-position-driver.test.ts
  • src/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.
@nwparker
nwparker force-pushed the nwparker/browser-pane-position-loop-idle branch from 8464f58 to 767f839 Compare November 1, 2026 23:30
… 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.
@nwparker
nwparker merged commit 9fe0adf into main Nov 2, 2026
48 checks passed
@nwparker
nwparker deleted the nwparker/browser-pane-position-loop-idle branch November 2, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant