Repository navigation
Free background browser tabs when the computer runs low on memory - #52667
Conversation
… never postpone due pressure checks, poll rarely while memory is healthy
…k, with no timer of its own
…ine ends that attempt
|
Performance review (perf-scan) on a6c8597 Verdict: PASS. I found no new timers, no new wakeups at idle, and no work that grows with the number of pages per tick. I checked Main finding: the 10 s memory sample isn't new. New or changed work, with trigger, population and bound
Scenarios
Six scan questions
Regression classes the diff touches
Nit, not a finding: Not checked: how the renderer handles the extra urgent free requests (their rate is capped at one per tick), Windows and Linux on real machines, and live CPU numbers. |
[Medium impact] The PR appears safe to merge, with no outstanding findings. SummaryAdds memory-triggered freeing of background browser pages through the existing Memory Saver protections.
Reviews (4) · Last reviewed commit: "test(memory): cover each platform's avai..." · Reviewed by Greptile |
|
Review status for Problem: hidden browser pages each keep a renderer process, about 55 MB apiece. On a 1,901-workspace profile with 30 of them, they were two thirds of the app's memory. Memory Saver freed them only after 4 awake hours, even when the computer was running out of memory. Change: when available memory is critically low (at most 400 MiB on Windows and Linux, 800 MiB on macOS including file cache), Orca frees the least recently seen hidden page that has been hidden at least 10 minutes. It frees at most one page per 10-second memory sample, through Memory Saver's existing path and protections. Turning Memory Saver off turns this off too. Verified:
Fixed during review:
Deferred (P2 and nits):
Final passes on this head: regression audit SAFE, perf-scan PASS, Claude re-review CLEAN. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
ELI5
When your computer is about to run out of memory, Orca now closes background browser tabs you haven't looked at in a while, oldest first, so the computer stays usable. When you go back to one, it reloads where you left it. Before this, Orca waited 4 hours no matter how little memory was left.
What Changed
system-memory-pressure.ts): Orca reads Electron'sprocess.getSystemMemoryInfo(), a synchronous system call that starts no other process.host-memory-sample-tick.ts), so it adds no timer and no wakeup.browser-page-urgent-discard.ts) keeps hidden pages in the order they were hidden, so finding the next page to free never scans every page.browser-page-idle-episode.tsholds the page record and the "hidden and waiting" rule; the scheduler and the hidden-page count used to repeat that rule.browser-memory-saver-settings-sync.ts) so the scheduler file stays under the line limit. Its code is unchanged.Why
On a fleet copy at 1,901 workspaces, 30 hidden browser pages took about 1.65 GB, two thirds of the app's memory. Users have reported the same pattern (20 background renderers taking 1.66 GB), and the crash channel shows renderer out-of-memory crashes on Windows. A timer measured in hours can't help when memory runs out within minutes.
This is the standard approach: free the least recently seen background page under critical system memory pressure, keep a short grace period for pages seen recently, and repeat at a fixed pace while the pressure lasts. Two alternatives were rejected:
Linked Issue
Fixes #
Visual Proof
N/A: no UI change. A freed page shows its normal reload when opened again, as Memory Saver pages already do.
Testing
Measured on Linux on head a6c8597, against main, with the same copy of a synthetic 1,901-workspace profile for both builds. The copy had 32 browser pages (16 opened the way a person would, 16 through the runtime), 30 chats and 40 terminals with 20,000 lines each, plus 126 workspace switches. The app's own memory reading was set to critically low for 14 minutes while the copy saw light use, one workspace switch a minute. Memory is PSS for all of Orca's processes:
Reopening a freed page: it reloaded in 654 ms with the same address, title and content. Its scroll position came back: it was scrolled to y=4321 before being freed. A page that was never freed shows in about 531 ms.
Freeing pace: one page every 10 seconds (measured gaps of 9,999 to 10,004 ms), oldest first. All 32 went through the normal admission.
Without simulated pressure: nothing is freed before Memory Saver's hours, as before.
browser-page-idle-discard.test.tscovers the state machine:Every test fails on main.
Tested on Linux only. The Windows and macOS thresholds use the fields Electron reports on those platforms and haven't been run there.
pnpm check:changedpasses.Performance
Risk
Level: Low
AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)