From 0cf69303741737f2b7fd0a0de024f5ecc0755985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Mon, 10 Jun 2024 21:47:29 +0200 Subject: [PATCH] Fix elevated CPU usage after ui_progress_bar_start/stop() is used After calling ``` ui_progress_bar_start("foo"); ... ui_progress_bar_stop(); ``` which should theoretically completely stop the progress bar, I get elevated CPU usage of the whole Geany process ~1% CPU on idle (and around 4% on macOS) compared to 0% after Geany launch before the status bar progress bar is used (e.g. by compiling). GTK seems to keep the widget connected to "tick callback" which causes the higher CPU (in fact, there's no gtk_progress_bar_stop() so it can't do it). The workaround to fix this problem is to call ``` gtk_progress_bar_set_fraction() ``` which switches the progress bar to the mode where it shows the user-provided progress and this removes the "tick callback". --- src/printing.c | 2 ++ src/ui_utils.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/printing.c b/src/printing.c index 4d64e2e029..b5a25a707e 100644 --- a/src/printing.c +++ b/src/printing.c @@ -292,6 +292,8 @@ static void end_print(GtkPrintOperation *operation, GtkPrintContext *context, gp if (dinfo == NULL) return; + /* see ui_progress_bar_stop() for more details on why this is called */ + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(main_widgets.progressbar), 0.0); gtk_widget_hide(main_widgets.progressbar); g_object_unref(dinfo->sci); g_object_unref(dinfo->layout); diff --git a/src/ui_utils.c b/src/ui_utils.c index 68d12f0ff8..c402d37233 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -2871,6 +2871,10 @@ void ui_progress_bar_stop(void) g_source_remove(progress_bar_timer_id); progress_bar_timer_id = 0; } + + /* hack to remove tick callback which is created for "activity mode" progress + * bars - without this it is called forever and causes elevated CPU usage */ + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(main_widgets.progressbar), 0.0); }