From 45505197d6fe5781ed66ba9968f2fc179d4df293 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 2 Apr 2020 13:06:18 +0100 Subject: [PATCH 1/2] gs-plugin-loader: Avoid calls to refine_wildcard() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a plugin doesn’t support `gs_plugin_refine_wildcard()`, there’s no need to call `call_vfunc()` for each app in a list of (likely a few hundred) apps for it to immediately return TRUE each time. Signed-off-by: Philip Withnall --- lib/gs-plugin-loader.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c index fef084232..8ab51db5f 100644 --- a/lib/gs-plugin-loader.c +++ b/lib/gs-plugin-loader.c @@ -790,20 +790,24 @@ gs_plugin_loader_run_refine_filter (GsPluginLoaderHelper *helper, return FALSE; } - /* use a copy of the list for the loop because a function called - * on the plugin may affect the list which can lead to problems - * (e.g. inserting an app in the list on every call results in - * an infinite loop) */ - helper->function_name = "gs_plugin_refine_wildcard"; - app_list = gs_app_list_copy (list); - for (guint j = 0; j < gs_app_list_length (app_list); j++) { - GsApp *app = gs_app_list_index (app_list, j); - if (gs_app_has_quirk (app, GS_APP_QUIRK_IS_WILDCARD) && - !gs_plugin_loader_call_vfunc (helper, plugin, app, NULL, - refine_flags, cancellable, error)) { - return FALSE; + if (gs_plugin_get_symbol (plugin, "gs_plugin_refine_wildcard") != NULL) { + /* use a copy of the list for the loop because a function called + * on the plugin may affect the list which can lead to problems + * (e.g. inserting an app in the list on every call results in + * an infinite loop) */ + app_list = gs_app_list_copy (list); + helper->function_name = "gs_plugin_refine_wildcard"; + + for (guint j = 0; j < gs_app_list_length (app_list); j++) { + GsApp *app = gs_app_list_index (app_list, j); + if (gs_app_has_quirk (app, GS_APP_QUIRK_IS_WILDCARD) && + !gs_plugin_loader_call_vfunc (helper, plugin, app, NULL, + refine_flags, cancellable, error)) { + return FALSE; + } } } + gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED); } -- GitLab From a24b1e0b28ce8b7c36fff81e4217ac106f6b5af0 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 2 Apr 2020 23:29:16 +0100 Subject: [PATCH 2/2] gs-plugin-loader: Only do an early refine if sorting results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `gs_plugin_loader_process_thread_cb()` refines the app list it’s working on twice: once with a minimal set of refine flags so that the app list can be sorted and truncated; and then again on the truncated app list with a wider set of refine flags. Finally, it sorts the results again (without truncation). Often, however, the truncation step is a no-op. In this case, the sorting and initial refine are unnecessary, but they were still being done. As both a refine and a sort happen later anyway, this was redundant. Adding a check to skip the initial refine if no truncation is going to happen reduced the time needed for a `get-category-apps` operation on a large category from 2.5s to 1.7s (-32%). Signed-off-by: Philip Withnall --- lib/gs-plugin-loader.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c index 8ab51db5f..74e9db58c 100644 --- a/lib/gs-plugin-loader.c +++ b/lib/gs-plugin-loader.c @@ -3062,6 +3062,7 @@ gs_plugin_loader_process_thread_cb (GTask *task, GsPluginRefineFlags filter_flags; GsPluginRefineFlags refine_flags; gboolean add_to_pending_array = FALSE; + guint max_results; /* these change the pending count on the installed panel */ switch (action) { @@ -3173,9 +3174,11 @@ gs_plugin_loader_process_thread_cb (GTask *task, break; } - /* refine with enough data so that the sort_func can do what it needs */ + /* refine with enough data so that the sort_func in + * gs_plugin_loader_job_sorted_truncation() can do what it needs */ filter_flags = gs_plugin_job_get_filter_flags (helper->plugin_job); - if (filter_flags > 0) { + max_results = gs_plugin_job_get_max_results (helper->plugin_job); + if (filter_flags > 0 && max_results > 0) { g_autoptr(GsPluginLoaderHelper) helper2 = NULL; g_autoptr(GsPluginJob) plugin_job = NULL; plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFINE, -- GitLab