GTK4 periodic signal to refresh data display

Hello, I would like to know the best way to repeatedly update some labels. Currently I use Gtk4.g_timeout_add(cb,ms) . cb being a callback retrieving new values and updating corresponding labels.
But it tends to render everything sluggish, REPL included…
Although I m not aware how to clean these signal after program closure …
Help appreciated
Thanks

How long does your callback take and how often is it being called? The function g_timeout_add calls it via the GTK event loop. If the callback takes a long time to return (more than say tens of milliseconds), it will prevent events and draws from being processed as often as needed to keep the UI interactive.

Lengthy computation and IO should be offloaded to a task on another thread. At the end of this other task you can update the label on the UI thread using g_idle_add. See Asynchronous UI · Gtk4.jl.

You can stop the timeout by returning false from the callback or by calling g_source_remove on the ID returned by g_timeout_add: see docstring for g_timeout_add.