GTK3 GtkFileChooserDialog wakes up every frame due to progress spinner
When a GtkFileChooserDialog is visible, GTK3 wakes up every 16ms as if there's an animation, but nothing changes, meaning it wastes ~2% CPU. It doesn't seem to matter which folder is open.
This doesn't seem to happen on GTK4; it just settles into sleeping.
Steps to reproduce
This does seem to happen with xdg-desktop-portal-gtk, so one option is to open a dialog through a file chooser portal and strace -p `pgrep -f xdg-desktop-portal-gtk`
.
Alternatively, run this program under strace:
/* build under GTK3 for the problem, but also compiles with GTK4;
* can still reproduce with gtk_init/gtk_main on GTK3.
*
* build command:
* cc minimal.c `pkg-config gtk+-3.0 --cflags --libs` -o minimal
*/
#include <gtk/gtk.h>
static void
activate (GApplication *app, void *data)
{
GtkWidget *fc = gtk_file_chooser_dialog_new ("Example", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, NULL);
g_signal_connect_swapped (fc, "destroy", G_CALLBACK (g_application_release), app);
gtk_window_present (GTK_WINDOW (fc));
g_application_hold (app);
}
int
main (int argc, char **argv)
{
GtkApplication *app = gtk_application_new (NULL, G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int ret = g_application_run (G_APPLICATION (app), argc, argv);
g_clear_object (&app);
return ret;
}
Current behavior
GTK wakes up every 16ms, presumably for a frame, but nothing changes.
Expected outcome
GTK maybe wakes up for animations, but then settles to poll(..., -1)
.
Version information
- GTK 3.24.38-4 (from Debian)
- GLib 2.77.2-1 (from Debian)
- Debian GNU/Linux trixie/sid [i.e. unstable] x86_64
Additional information
sample strace output on GTK3
...
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 16) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 17) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 16) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 17) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 17) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 16) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 17) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 17) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 16) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 17) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 16) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 17) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 17) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 16) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 16) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 16) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}, {fd=11, events=POLLIN}], 3, 16^Cstrace: Process 126123 detached
<detached ...>