diff options
author | Richard Hughes <richard@hughsie.com> | 2016-11-02 16:04:31 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2016-11-02 16:04:31 +0000 |
commit | 997313d3ea19eaf99b2583572a2a8de6a8ebd149 (patch) | |
tree | 7e2c767e4454af2da91ef6db3844305d56b958ba | |
parent | 8e5cb0858457db5718e9c0f175adb82c805342de (diff) | |
download | appstream-glib-997313d3ea19eaf99b2583572a2a8de6a8ebd149.tar.gz |
Use multiple threads to load the search cache
This speeds up loading the token cache by 30ms on x64.
-rw-r--r-- | libappstream-glib/as-store.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c index 0035841..d8a6c5d 100644 --- a/libappstream-glib/as-store.c +++ b/libappstream-glib/as-store.c @@ -2933,13 +2933,20 @@ as_store_search_per_user (AsStore *store, return TRUE; } +static void +as_store_load_search_cache_cb (gpointer data, gpointer user_data) +{ + AsApp *app = AS_APP (data); + as_app_search_matches (app, NULL); +} + /** * as_store_load_search_cache: * @store: a #AsStore instance. * * Populates the token cache for all applications in the store. This allows * all the search keywords for all applications in the store to be - * pre-processed at one time rather than on demand. + * pre-processed at one time in multiple threads rather than on demand. * * Note: Calling as_app_search_matches() automatically generates the search * cache for the #AsApp object if it has not already been generated. @@ -2951,6 +2958,7 @@ as_store_load_search_cache (AsStore *store) { AsStorePrivate *priv = GET_PRIVATE (store); guint i; + GThreadPool *pool; g_autoptr(AsProfileTask) ptask = NULL; /* profile */ @@ -2958,11 +2966,15 @@ as_store_load_search_cache (AsStore *store) "AsStore:load-token-cache"); g_assert (ptask != NULL); - /* load the token cache for each app */ + /* load the token cache for each app in multiple threads */ + pool = g_thread_pool_new (as_store_load_search_cache_cb, + store, 4, TRUE, NULL); + g_assert (pool != NULL); for (i = 0; i < priv->array->len; i++) { AsApp *app = g_ptr_array_index (priv->array, i); - as_app_search_matches (app, NULL); + g_thread_pool_push (pool, app, NULL); } + g_thread_pool_free (pool, FALSE, TRUE); } /** |