resources icon indicating copy to clipboard operation
resources copied to clipboard

CPU & GPU power savings: Resources does not use the GTK "suspended" state to stop doing GUI updates when the window is not visible

Open nekohayo opened this issue 8 months ago • 1 comments

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

  1. Launch btop in a terminal, filter for "resources"
  2. Launch Resources, with normal refresh speed
  3. Minimize Resources and/or move it to another virtual workspace so that it is invisible
  4. 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_toplevel that receives the suspended event.
GTK4 for example plumbs this to GDK_TOPLEVEL_STATE_SUSPENDED.

Here are examples of implementations:

  • In your case, the closest example would be GNOME System Monitor, see the cb_main_window_suspended function in interface.cpp
  • In WebKitGTK
  • In Fragments where they reduce polling in that context

nekohayo avatar Mar 31 '25 14:03 nekohayo

Hi, thanks for the issue. I will look into implementing that, that should hopefully be relatively straight forward.

nokyan avatar Mar 31 '25 14:03 nokyan

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?

nokyan avatar Jul 15 '25 16:07 nokyan