Gtk list store and thread safety

My application uses gtk_list_store to hold about a 100,000 rows of data. Obviously loading this data takes a while. First improvement was to load 5-10 rows in idle cycles that slightly improved UI performance where stuttering was minimal. Then I used a worker thread to create a local gtk_list_store and load data into it locally within the thread. At this point the list store is not shared with the UI thread so that there are no views or filtered models to which it is attached. Once all data is loaded, the model reference is copied to a class member (yes I am using gtkmm3) and a Glib::Dispatcher is used to notify the UI thread. I DID NOT notice any issues while initial testing, performance was also good (several orders faster than the idle cycle method), especially since my embedded target has two CPU cores.

Is it legal from a thread safety point of view to do it this way, provided that the list store is completely local to the thread until all records are loaded?

1 Like

You can load the GtkListStore in a thread and then move the model to the UI main thread, and assign it to a GtkTreeView (or any other GTK widget that displays the model); what you cannot do after that is to use a thread to add/remove/update rows.

The performance of models and tree views in GTK3 has a hard ceiling because the model API has no bulk operations, and the view implementation emits signals for every cell. Loading the data inside a thread or inside an idle function is pretty much the same; you may notice issues with the view once you assign the model, but in theory the view should still reasonably scale in the 10k/100k rows range. For anything above that order of magnitude, you’ll have to start considering GTK4 and the new recycling list views it introduces.

2 Likes