Skip to content

perf(browser): throttle idle guests with owned activity exceptions - #282

Merged
sambitcreate merged 3 commits into
mainfrom
feature/perf-browser-throttling
Sep 28, 2026
Merged

sambitcreate merged 3 commits into
mainfrom
feature/perf-browser-throttling

Conversation

@sambitcreate

@sambitcreate sambitcreate commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

Embedded browser guests previously disabled background throttling for their entire lifetime. Ordinary guests now use throttling, with reference-counted exceptions owned by active automation, screenshots and recording. Abort, recording settlement, crash and close release the appropriate exception.

Validation: 154 browser tests; native Electron lifecycle test covering hidden capture, automation, cancellation, real recording/crash and close; app/E2E type checks; scoped lint; full build; CI discovery/policy checks. The original native policy check fails and the changed policy passes for three hidden guests. Fresh-context GPT-6 Astra medium review found no actionable issues and passed 16 focused tests.

Attached-window activity exception: Electron combines throttling sources at the containing window, so an active guest lease can also permit host/sibling drawing. This is accepted during explicit browser work; ownership, not a universal five-minute timer, bounds the lease. Documentation identifies individual deadlines and unbounded debugger/export waits. Extended native coverage exercises attached guests, actual macOS minimization, overlapping cancellation, explicit recording stop and automatic-stop cleanup. Fresh-context follow-up review independently passed 154 browser tests and the native fixture and verified pinned Electron source; no actionable findings remain. Linux uses hide/show in the fixture and has not been executed locally.

Evidence: docs/performance/browser-throttling.md and its raw attached-window JSON. Policy and functional behavior are measured; CPU/GPU/energy savings and Linux native behavior remain unmeasured. Existing detached-page animation-frame behavior is unchanged.

@very-hermes-bot

very-hermes-bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Hermes Review Bot

Confidence: 5

Engine: agy/gemini-3.8-flash-high
Review mode: full
Head: deec0c010740e8bf81d41fb93f5c8550f03208c7
Generated: 2026-09-28T03:16:56+00:00
Reviews: 1

Summary

Embedded browser guest WebContents now initialize with background throttling enabled (backgroundThrottling: true) instead of disabling throttling permanently at creation. A new BrowserBackgroundThrottling helper manages temporary reference-counted leases that disable guest throttling (setBackgroundThrottling(false)) only while active operations run: during action-queue execution, snapshot/PiP/annotation captures, and active screencast recordings. Leases are released immediately upon command completion or signal abortion, with renderer crash and tab closure triggering explicit resets and recorder finalization. Maintainers should double-check that the accepted Electron window-wide compositor behavior—where an unthrottled guest can allow background drawing for other attached sibling views in that host window—remains acceptable for active capture and automation workloads.

Confidence Score: 5/5

5/5 — All changed implementation files, error handling paths, lifecycle boundaries (cancellation, crash, and close), unit tests, and native standalone e2e fixtures were completely traced and verified against Electron contracts and existing patterns.

📁 Important Files Changed
  • main/services/browser/background-throttling.ts: Implements BrowserBackgroundThrottling to provide reference-counted leases, abort-signal listeners, idempotent releases, and reset logic for guest WebContents throttling.
  • main/services/browser/service.ts: Defaults guest WebContents to backgroundThrottling: true, acquires leases across action queue execution, page capture, and recording lifetimes, and resets throttling on tab crash and teardown.
  • main/services/browser/background-throttling.test.ts: Unit tests validating overlapping leases, abort cancellation before native settlement, crash reset isolation from replacement leases, and safe teardown on destroyed guests.
  • tests/e2e/browser-throttling-native.ts: Standalone Electron test harness exercising native scheduling policy across idle tabs, hidden timer automation, capture, cancellation, WebM recording, window minimization/hiding, auto-stop timer expiration, and renderer crash.
  • tests/e2e/browser-throttling.spec.ts: Playwright spec bundling and running the native fixture in an isolated Electron child process with proper headless/GPU flags and Linux display environment forwarding.
  • docs/performance/browser-throttling.md & .memory/perf-browser-throttling.md: Documents DP-01 performance investigation, baseline comparisons, native execution evidence, and the accepted host-window compositor aggregation behavior.
  • docs/performance/browser-throttling-attached-native.json: Raw test output recording native background throttling states, frame metrics, and auto-stop delay verification.

Findings

No findings.

📊 Sequence Diagram
sequenceDiagram
    autonumber
    participant Q as BrowserActionQueue
    participant S as BrowserService
    participant T as BrowserBackgroundThrottling
    participant WC as Guest WebContents
    participant R as Recorder Window

    Note over WC: Initial state: backgroundThrottling = true

    rect rgb(240, 248, 255)
    Note over Q,WC: Action Queue Execution (e.g. evaluate / click)
    Q->>T: acquire(signal)
    T->>WC: setBackgroundThrottling(false)
    Q->>WC: execute action
    Q->>T: release()
    T->>WC: setBackgroundThrottling(true)
    end

    rect rgb(255, 250, 240)
    Note over S,R: Recording Lifecycle
    S->>T: acquire() [recording lease]
    T->>WC: setBackgroundThrottling(false)
    S->>R: start recording session
    Note over S,R: Recording in progress (unthrottled)
    S->>R: stop / auto-stop / close / crash
    R-->>T: "closed" event triggers release()
    T->>WC: setBackgroundThrottling(true)
    end
Loading

Machine-Readable Findings

[]

Last reviewed commit: deec0c010740
Reviews (1) · Comment /hermes review to trigger a new review · /hermes review full for full re-review

@pullfrog pullfrog 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.

Important

A guest activity lease can keep the entire host BrowserWindow and its other displayed contents drawing frames while backgrounded or minimized; please account for this window-wide impact before merge.

Reviewed changes This review covers head 0a56d0c, which changes browser guest throttling and adds lease lifecycle tests and a native Electron fixture.

  • Default policy and ownership. New guests use normal background throttling, with scoped leases around queued actions, captures, and recordings.
  • Lifecycle and evidence. Abort, close, and crash release or reset ownership; the added tests cover these policy and lifecycle paths.

Local app and E2E type checks and Playwright discovery pass. npm run test:browser reports 153/154 because the Playwright Chromium binary is unavailable; the focused native fixture cannot start because Electron's Linux SUID sandbox is not configured.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using GPT Luna | 𝕏

Comment thread main/services/browser/background-throttling.ts

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes This incremental review covers the two commits since the prior Pullfrog review, documenting the accepted window-wide throttling exception and extending native coverage for attached guests, background operation, overlapping ownership, and recording cleanup.

  • Documented the host-window effect. Added pinned Electron aggregation evidence and clarified that operation ownership, rather than a universal timer, bounds the active exception.
  • Extended native lifecycle coverage. Exercised attached host and sibling views through automation, overlapping cancellation, explicit stop, and deterministic auto-stop cleanup.

Pullfrog  | View workflow run | Using GPT Luna | 𝕏

@sambitcreate
sambitcreate merged commit cb169c6 into main Sep 28, 2026
23 checks passed
@sambitcreate
sambitcreate deleted the feature/perf-browser-throttling branch September 28, 2026 22:08
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.

2 participants