From 3299cbf8254a8bc5a39f48836d8d4dc1b3eaab87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Fri, 12 Nov 2021 12:20:39 +0100 Subject: [PATCH] Parallelize thumbnail loading GLib makes this easy. They should all be local, and fast to access, so the CPU is the limit. --- fastiv-browser.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/fastiv-browser.c b/fastiv-browser.c index e4ffa4e..385096f 100644 --- a/fastiv-browser.c +++ b/fastiv-browser.c @@ -561,6 +561,14 @@ rescale_thumbnail(cairo_surface_t *thumbnail) return scaled; } +static void +entry_add_thumbnail(gpointer data, G_GNUC_UNUSED gpointer user_data) +{ + Entry *self = data; + self->thumbnail = + rescale_thumbnail(fastiv_io_lookup_thumbnail(self->filename)); +} + void fastiv_browser_load(FastivBrowser *self, const char *path) { @@ -577,15 +585,17 @@ fastiv_browser_load(FastivBrowser *self, const char *path) continue; gchar *subpath = g_build_filename(path, filename, NULL); - g_array_append_val(self->entries, - ((Entry){ - .thumbnail = - rescale_thumbnail(fastiv_io_lookup_thumbnail(subpath)), - .filename = subpath, - })); + g_array_append_val( + self->entries, ((Entry) {.thumbnail = NULL, .filename = subpath})); } g_dir_close(dir); + GThreadPool *pool = g_thread_pool_new( + entry_add_thumbnail, NULL, g_get_num_processors(), FALSE, NULL); + for (guint i = 0; i < self->entries->len; i++) + g_thread_pool_push(pool, &g_array_index(self->entries, Entry, i), NULL); + g_thread_pool_free(pool, FALSE, TRUE); + // TODO(p): Sort the entries. gtk_widget_queue_resize(GTK_WIDGET(self)); }