CPU & GPU power savings: Resources does not use the GTK "suspended" state to stop doing GUI updates when the window is not visible
Is there an existing issue for this?
- [x] I searched the existing issues and did not find anything similar.
Current Behavior
High CPU usage (as seen in #478) remains high even when the app is minimized, on another workspace, or otherwise visually obscured.
From looking at https://github.com/search?q=repo%3Anokyan%2Fresources%20suspend&type=code it does not seem like you use GTK4's "suspended" state.
Expected Behavior
You can achieve this by connecting to GTK4's "suspended" state signal and freeze everything non-essential when the user can't actually see the window. GNOME System Monitor's commit description when that power saving feature was initially introduced 11 years ago was:
If the window is minimized, stop background data collection to minimize wakeups. On window restore/focus, start it again.
…but it also freezes its UI refreshes/repaints, too.
See examples of implementations further below.
Steps to Reproduce
- Launch
btopin a terminal, filter for "resources" - Launch Resources, with normal refresh speed
- Minimize Resources and/or move it to another virtual workspace so that it is invisible
- Observe Resources' continued CPU usage, in btop or gnome-system-monitor
Debug Logs
N/A
Environment
Version 1.8.0 from Flathub on Fedora 41's GNOME 47 Wayland session
Anything Else?
See https://gitlab.gnome.org/GNOME/mutter/-/issues/3634 for the detailed general discussion around this, as reference.
It's the owner of the
xdg_toplevelthat receives the suspended event.
GTK4 for example plumbs this toGDK_TOPLEVEL_STATE_SUSPENDED.
Here are examples of implementations:
- In your case, the closest example would be GNOME System Monitor, see the
cb_main_window_suspendedfunction in interface.cpp - In WebKitGTK
- In Fragments where they reduce polling in that context
Hi, thanks for the issue. I will look into implementing that, that should hopefully be relatively straight forward.
Hi, in the suspend branch I've implemented halting graphical updates when Resources detects being suspended. In my testing this makes Resources' (the graphical process, i.e. resources not resources-processes) CPU usage go down from 0.1-0.4% to 0.0-0.1%. Do you mind testing it as well?