Repository navigation
Conversation
…busy (Louis-CFM#792) With the Coucou window open, one WebKitWebProcess stayed at about 100 % of a core on Linux (KDE Plasma 5.27, X11, WebKitGTK 2.52.6), focused or not. Measured per canvas, almost all of it was the sleeping Mochi of an empty page (the Dictation page's empty history, shown at every launch until you dictate): 60-75 ms a frame, growing over time, for a 64x64 canvas. Its z's grow as they rise, so each frame set `ctx.font` to a new fractional size, and WebKitGTK resolved and cached a new font every time. The z is now drawn at one font size (32 px) and scaled: 0.3 ms a frame. The window's canvases are also drawn at 30 frames a second with the focus and 10 behind other windows, instead of 60: WebKitGTK paints and composites each changed canvas in software, which cost about half a core at 60 even with the font fixed. Mochi's engine is stepped in pieces of at most 1/30 s, since its mouth spring is unstable above 0.08 s per step. CPU of the whole app with the window open (Ubuntu 24.04, X11, RTX 2060): 0.5.9: ~100 % focused, ~100 % behind other windows font fix only (60 fps): 49 % 46 % font fix + 30/10 fps: 24 % 10 % Nothing looks different apart from the frame rate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rahul05ranjan
left a comment
There was a problem hiding this comment.
I simulated frameDue/frameInterval outside the browser to sanity-check the cadence math and it holds up: at 60 Hz with ±0.7 ms jitter you get exactly 30 draws/s with focus, 10/s behind other windows, and 30/s on a 120 Hz screen as well (with the 4 ms tolerance the frame at 34.7 ms still qualifies). A 50 Hz display lands at 25/s, which is the sensible floor. The starved ? 33 : 250 fallback timer interacts correctly with the 100 ms background interval too.
The substep loop in stepEngine also checks out — for (left = dt; left > 1e-6; left -= MAX_STEP) update(min(left, MAX_STEP)) sums to exactly dt, so the spring speeds at 10 fps match the 30 fps path; and pairing the raised dt cap (0.05 → 0.12) with 1/30 s substeps is the right way to keep the ω₀ = 2π/0.25 mouth spring stable at the background rate.
Two small things, neither blocking:
- The
-4tolerance is documented as "a quarter of a 60 Hz frame", but it's just a constant. It behaves at 120/50 Hz as verified above, so this is purely a comment-vs-code precision nit — a named constant (JITTER_MS) would make the intent greppable if someone ever tunes FPS_BACKGROUND. - In the
!frameDueearly return the skipped frames leavelastuntouched, sodtfor the next drawn frame includes all the skipped time (up to the 0.12 cap). That's clearly the design — but it means a window regaining focus after a long unfocused stretch draws one frame at ~0.12 s. The substepping absorbs it, just noting the walk will visibly jump on that single frame.
The Z_FONT single-size + x.scale change is a clean equivalent of the old sz * 1.9 size (position is (0,0), so the transform only affects the glyph), and scoping it inside the existing save/restore is right.
What was wrong
Follow-up to #792. Since #817 the Coucou window stops animating when it is hidden, but while it is open one
WebKitWebProcessstill sits at about 100 % of a CPU core on Linux, focused or not, and the window stutters.Setup: Ubuntu 24.04, KDE Plasma 5.27 (X11), WebKitGTK 2.52.6, RTX 2060 (driver 580).
WEBKIT_DISABLE_DMABUF_RENDERER=1andWEBKIT_DISABLE_COMPOSITING_MODE=1change nothing, as in #792.Why
I timed each canvas in the
hero.tsloop. The bands, glow cards and walking Mochis take 0.1–0.3 ms a frame each. One canvas takes 60–75 ms a frame, and gets slower over time: the 64×64 sleeping Mochi of an empty page (emptyState()→liveMochi()). The Dictation page shows it in its empty history, and the window opens on that page, so everyone sees it until they dictate something.Its z's grow as they rise (
sz = R * p.size * (1 + k * 0.4)indrawParticles), so every frame setsctx.fontto a new fractional size ("700 7.3412px system-ui, …"). WebKitGTK resolves and caches a new font for each one.With that fixed, the window still took about half a core at 60 fps: WebKitGTK paints and composites each changed canvas in software, so that cost follows the frame rate.
The fix
mochi/engine.ts: the z is drawn at one font size (32 px) and scaled. 60–75 ms → 0.3 ms a frame. The island's sleeping Mochi uses the same engine and gets the fix too.hub/frames.ts,hub/hero.ts: the Coucou window's canvases are drawn at 30 frames a second with the focus and 10 behind other windows, instead of 60. The decision is inframes.ts(frameInterval,frameDue), next toshouldAnimate.hub/hero.ts: Mochi's engine is stepped in pieces of at most 1/30 s (stepEngine), because the mouth spring (ω₀ = 2π/0.25) is unstable above about 0.08 s a step.dtis capped at 0.12 s instead of 0.05 s, so walks and drift keep their speed at 10 fps. The Mac's Mochi at 60 fps open, 30 folded: no more 120 Hz redraws (#1116) #1131 does the same withMochiFrameClock.tests/hub-frames.test.mjs: 4 tests for the frame rate (every other frame of a 60 Hz screen with the focus, with jitter; one in six without; the first frame always drawn).Nothing looks different apart from the frame rate. No Rust changes.
Measured
CPU of the whole app (main process + all WebKit processes), Coucou window open on the Dictation page, 20 s samples, two runs each, Ryzen 9 5950X:
main(ab98143), fresh install (empty history)With a non-empty dictation history (no sleeping Mochi on the page), the frame rate alone goes from 35–42 % to about 20 % focused and 10 % behind other windows.
On 0.5.9, to split the two changes:
Window closed: about 0 %, as since #817.
How to check
top -p $(pgrep -d, -P $(pgrep -xo coucou)): before, oneWebKitWebProcessat ~100 %; after, ~20–25 % focused and ~7–10 % behind another window.Tests
npx tsc --noEmit: cleannpm test(Node 22): 570 / 570 passnpm run tauri build: no new warnings (the fournever usedwarnings in a Linux build are Windows-only helpers, unchanged)🤖 Generated with Claude Code
https://claude.ai/code/session_018gKYX7ijeFjmrb97PJB2FT