mirror of
https://github.com/storytold/soundcraft.git
synced 2026-10-29 13:06:49 -06:00
The app sent the window title to egui on every frame. Each viewport command asks for another frame, so the window redrew at the display's refresh rate with nothing happening: 35-43% of a CPU core and 13-20% of the GPU per window on a 120 Hz Mac. While the window was covered or minimized, eframe runs only App::logic, with no vsync to pace it, and the same request kept one core at 100%. The title is now sent only when it changes. The last title sent is kept in egui's context data rather than compared with the window's, because winit can't read a title back on X11 or Wayland. Some work only ran because another frame always came, so an idle window still wakes once a second, and every 30 ms while a plugin editor is open. Autosave and the macOS menu bar's throttled refresh run on frames, and plugin editors are native windows egui never hears from: their edits (VST3 performEdit, CLAP output events) and main-thread requests are serviced on frames. egui takes its predicted frame time off every delay, so it is added back. The menu bar can now trail a shortcut by up to a second instead of 250 ms. Playback, falling meters, pending screenshots and scripted input ask for the next frame from ui() instead of logic(). eframe skips ui() for a covered or minimized window, so a hidden window runs on the heartbeat instead of spinning, and egui redraws it as soon as it shows again. Autosave was timed by egui's frame clock, which stands still while the window is hidden, so a modified session wasn't autosaved until the window showed again. It is timed by the wall clock now. Only the desktop app sets an autosave folder, so the web build never reads it. Tests check that an unchanged title sends no command, that only a shown window animates while a hidden one wakes once a second, and that a hidden window still autosaves. Measured on a 120 Hz MacBook with a release build, the demo session and audio off: an idle Edit window went from 35-43% CPU and 13-20% GPU to 1.5% and 0.4% (the insertion point blinks), the Mix window to 0.2%, and a covered window, idle or playing, from ~100% CPU to 0%.