Repository navigation
Conversation
|
Verdict: the diagnosis is right, but the fix is in the wrong layer. I'd change direction rather than merge this. The diagnosis holds. wry 0.57 handles Why fixing it for faces alone is not enough. The same false "visible" affects every part of the app that relies on
This PR adds a second, face-only source of truth that polls the native window over IPC. All the other features stay wrong on Windows. Suggested direction. In the desktop Rust side (Windows), track each window's minimise/hide/show state and call
Then Other notes on the diff:
Not ready to merge as it stands. 🤖 Generated with Codeg |
…cused Minimising a WebView2 window leaves `document.visibilityState` at "visible", so a minimised Codeg kept drawing its faces — 0.12 core of pure idle cost, measured on this build with an idle workspace open. The native window state is the honest signal: the first face that mounts follows `isVisible`/`isMinimized` and marks itself `data-hidden`, which the stylesheet already holds still. The mark is taken off again on restore, and the tracking is one shared listener for every face rather than one per face. Losing focus is deliberately NOT part of it. A window beside a terminal is on screen; freezing a face every time the person types elsewhere would read as a broken app rather than a thrifty one.
da5c200 to
c0f629f
Compare
|
Closing this in favour of #1433, which takes the route you pointed at. You were right that the root cause is below the page: #1433 keeps each window's shown/minimised state and mirrors it into Measured on a build without it: 0.478 core on screen, 0.025 core minimised, 0.365 core restored, with Thanks for the precise diagnosis — it saved me from shipping the same fix in the wrong layer twice. |
The problem
A minimised Codeg goes on drawing its faces. Measured on this machine (20-core Windows 11, WebView2, an idle workspace with two faces in it), sampling the process over a minute:
A window nobody can see costs 98% of what a window on screen costs. The animation work is not the biggest single item in an idle process — that remains the per-tab agent keepalive — but it is the one that should cost nothing, and it is the one a laptop on battery pays for while the lid is closed.
Why the existing gate does not catch it
bot-face-motion.tsalready had a "nobody is looking" gate, and the stylesheet already knows how to hold a face still (data-hidden→animation-play-state: paused). The gate readdocument.visibilityState.On Windows, minimising a WebView2 window leaves the document
"visible". That was measured, not assumed: with the window minimised,document.visibilityState === "visible",document.hidden === false, and the faces were stillplay: running. So the gate was written against a signal that never fires on the platform most of these windows run on.The change
The native window state is the honest signal there, so the first face that mounts starts following it:
isVisible()/isMinimized()from@tauri-apps/api/window, re-read ononResizedandonFocusChanged(a minimised window reports a resize; restore reports another one).data-hiddenis what does the work: the stylesheet's pause rule was already there, this only feeds it.Losing focus is deliberately not "unseen". A window sitting beside a terminal is fully on screen; a face that froze every time the person typed elsewhere would look broken, and this app is often used exactly that way. The predicate is
!isVisible || isMinimized.Verification
Measured on a locally built
--no-bundlebinary (Windows 11, 20 cores, WebView2), one minute of sampling per state, per-process CPU counters, the app's own processes only (codeg.exe+msedgewebview2.exe; its agent children counted separately):data-hiddenabsent,animation-play-state: runningdata-hidden="",animation-play-state: pausedAn earlier binary measured the same way over the same workspace shape gave 0.123 → 0.094 core (0.76×); the shape of the saving depends on how many faces and tabs are on screen, so the invariant worth relying on is that minimised is strictly cheaper and nothing animates off screen. A CPU profile of a minimised window shows 99.2% idle in JS, i.e. what remains is the compositor and the browser process, not this app's timers.
RSS is unchanged in both states (~1206 MB for the app's processes in this session, ~454 MB in agent children), so nothing here trades CPU for memory.
bot-face-motion.test.ts: a faked native window is minimised → the face is markeddata-hidden; restored → the mark is gone; focus alone → the face keeps drawing;document.visibilityState = "hidden"→ marked even if the native window claims otherwise.bot-avatar.test.tsxunchanged and passing (41/41 together with the new file),tsc --noEmitclean.Not changed
The animation itself, its timing, and how it looks with a window on screen. This only decides whether the browser should spend frames on it, and it never pauses anything the owner can see.
CI
Frontend (lint + vitest + build)green (18m16s — 14,787 tests, all passing on the full suite),Rust desktop on windows-latestandRust desktop on ubuntu-22.04green,cli/servergreen on both. One lint failure on the way there was aprettier/prettierwrap inbot-face-motion.test.ts, fixed inf76349598.Rust desktop on macos-latestreportscancelledafter 54m51s with no uploaded log — the same on #1429 and on this branch, which touches no Rust file.