Skip to content

perf(windows): lazily create tray WebView2 and release it when idle - #238

Open
Bl0ck154 wants to merge 2 commits into
Lampese:mainfrom
Bl0ck154:upstream/perf-lazy-windows-tray-20261119
Open

Bl0ck154 wants to merge 2 commits into
Lampese:mainfrom
Bl0ck154:upstream/perf-lazy-windows-tray-20261119

Conversation

@Bl0ck154

@Bl0ck154 Bl0ck154 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Why this helps

On Windows, Codex Switcher currently starts an invisible WebView2 just for the tray popup, even if you never open that menu. Hiding the popup leaves that browser process around. It's extra memory for something most people only check occasionally.

This PR creates the tray popup when it's first opened and releases it after 90 seconds hidden. The native tray menu, account switching and background quota updates remain available. Opening the popup after it has been released may take a little longer.

What changed

  • Create the Windows popup on demand, leaving macOS behavior as it is.
  • Cancel idle cleanup when the popup is reopened and ignore events from an older instance.
  • Handle the first tray click even if React hasn't registered its event listener yet, and clean up late subscriptions when the popup is destroyed.
  • Add a regression test for the idle cleanup conditions.

Testing

I've already tested the Windows optimization work in my own fork, including RAM measurements with the Switcher open and in the tray. Before those changes, I measured around 436 MB with the window open and 365 MB in the tray (Switcher plus WebView2). In the newer build I saw around 275 MB open and 167–233 MB in the tray after a fresh PC startup.

Those are real observations from my fork, which includes other memory optimizations as well. They aren't an isolated before/after benchmark for this three-file PR, and the results can vary with runtime conditions.

This branch is based directly on upstream main. All six CI checks passed: Rust tests/format, Windows and macOS compilation, frontend, Linux startup and updater. A Windows GUI smoke test of this exact upstream patch would still be useful before merging.

Related but separate from #222, which addresses tray context-menu refresh behavior.

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