[gnome-software/wip/hughsie/libxmlb: 2/2] Use the new xb_builder_fixup_set_max_depth() for a pretty dramatic speedup



commit e918c2776863d5a67304028a4563f100c1cd6e9e
Author: Richard Hughes <richard hughsie com>
Date:   Fri Oct 19 16:22:36 2018 +0100

    Use the new xb_builder_fixup_set_max_depth() for a pretty dramatic speedup
    
    If we're fixing <component> then limit the traverse depth to 2 and save a huge
    number of strcmp's when compiling a new binary blob.

 meson.build                        |  2 +-
 plugins/core/gs-plugin-appstream.c | 71 ++++++++++++++++++++++++--------------
 plugins/flatpak/gs-flatpak.c       | 68 ++++++++++++++++++++++--------------
 3 files changed, 90 insertions(+), 51 deletions(-)
---
diff --git a/meson.build b/meson.build
index dd6f1a33..bea407de 100644
--- a/meson.build
+++ b/meson.build
@@ -98,7 +98,7 @@ conf.set('HAVE_LINUX_UNISTD_H', cc.has_header('linux/unistd.h'))
 
 appstream_glib = dependency('appstream-glib', version : '>= 0.7.14')
 gdk_pixbuf = dependency('gdk-pixbuf-2.0', version : '>= 2.32.0')
-libxmlb = dependency('xmlb', version : '>= 0.1.2', fallback : ['libxmlb', 'libxmlb_dep'])
+libxmlb = dependency('xmlb', version : '>= 0.1.3', fallback : ['libxmlb', 'libxmlb_dep'])
 gio_unix = dependency('gio-unix-2.0', version : '>= 2.56.0')
 gmodule = dependency('gmodule-2.0')
 gtk = dependency('gtk+-3.0', version : '>= 3.22.4')
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index 67a36e25..8ce04e82 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -65,7 +65,7 @@ gs_plugin_destroy (GsPlugin *plugin)
 }
 
 static gboolean
-gs_plugin_appstream_upgrade_cb (XbBuilderSource *self,
+gs_plugin_appstream_upgrade_cb (XbBuilderFixup *self,
                                XbBuilderNode *bn,
                                gpointer user_data,
                                GError **error)
@@ -87,7 +87,7 @@ gs_plugin_appstream_upgrade_cb (XbBuilderSource *self,
 }
 
 static gboolean
-gs_plugin_appstream_add_pkgname_cb (XbBuilderSource *self,
+gs_plugin_appstream_add_pkgname_cb (XbBuilderFixup *self,
                                    XbBuilderNode *bn,
                                    gpointer user_data,
                                    GError **error)
@@ -98,7 +98,7 @@ gs_plugin_appstream_add_pkgname_cb (XbBuilderSource *self,
 }
 
 static gboolean
-gs_plugin_appstream_add_icons_cb (XbBuilderSource *self,
+gs_plugin_appstream_add_icons_cb (XbBuilderFixup *self,
                                  XbBuilderNode *bn,
                                  gpointer user_data,
                                  GError **error)
@@ -111,7 +111,7 @@ gs_plugin_appstream_add_icons_cb (XbBuilderSource *self,
 }
 
 static gboolean
-gs_plugin_appstream_add_origin_keyword_cb (XbBuilderSource *self,
+gs_plugin_appstream_add_origin_keyword_cb (XbBuilderFixup *self,
                                           XbBuilderNode *bn,
                                           gpointer user_data,
                                           GError **error)
@@ -140,6 +140,7 @@ gs_plugin_appstream_load_appdata_fn (GsPlugin *plugin,
                                     GError **error)
 {
        g_autoptr(GFile) file = g_file_new_for_path (filename);
+       g_autoptr(XbBuilderFixup) fixup = NULL;
        g_autoptr(XbBuilderSource) source = xb_builder_source_new ();
 
        /* add source */
@@ -151,9 +152,11 @@ gs_plugin_appstream_load_appdata_fn (GsPlugin *plugin,
        }
 
        /* fix up any legacy installed files */
-       xb_builder_source_add_node_func (source, "AppStreamUpgrade",
-                                        gs_plugin_appstream_upgrade_cb,
-                                        plugin, NULL);
+       fixup = xb_builder_fixup_new ("AppStreamUpgrade",
+                                     gs_plugin_appstream_upgrade_cb,
+                                     plugin, NULL);
+       xb_builder_fixup_set_max_depth (fixup, 3);
+       xb_builder_source_add_fixup (source, fixup);
 
        /* success */
        xb_builder_import_source (builder, source);
@@ -220,6 +223,7 @@ gs_plugin_appstream_load_desktop_fn (GsPlugin *plugin,
                                     GError **error)
 {
        g_autoptr(GFile) file = g_file_new_for_path (filename);
+       g_autoptr(XbBuilderFixup) fixup = NULL;
        g_autoptr(XbBuilderSource) source = xb_builder_source_new ();
 
        /* add support for desktop files */
@@ -229,9 +233,11 @@ gs_plugin_appstream_load_desktop_fn (GsPlugin *plugin,
                                         NULL, NULL);
 
        /* add a dummy package name */
-       xb_builder_source_add_node_func (source, "AddDesktopPackageName",
-                                        gs_plugin_appstream_add_pkgname_cb,
-                                        plugin, NULL);
+       fixup = xb_builder_fixup_new ("AddDesktopPackageName",
+                                     gs_plugin_appstream_add_pkgname_cb,
+                                     plugin, NULL);
+       xb_builder_fixup_set_max_depth (fixup, 2);
+       xb_builder_source_add_fixup (source, fixup);
 
        /* add source */
        if (!xb_builder_source_load_file (source, file,
@@ -308,6 +314,9 @@ gs_plugin_appstream_load_appstream_fn (GsPlugin *plugin,
        g_autoptr(GError) error_local = NULL;
        g_autoptr(GFile) file = g_file_new_for_path (filename);
        g_autoptr(XbBuilderNode) info = NULL;
+       g_autoptr(XbBuilderFixup) fixup1 = NULL;
+       g_autoptr(XbBuilderFixup) fixup2 = NULL;
+       g_autoptr(XbBuilderFixup) fixup3 = NULL;
        g_autoptr(XbBuilderSource) source = xb_builder_source_new ();
 
        /* add support for DEP-11 files */
@@ -332,19 +341,25 @@ gs_plugin_appstream_load_appstream_fn (GsPlugin *plugin,
        xb_builder_source_set_info (source, info);
 
        /* add missing icons as required */
-       xb_builder_source_add_node_func (source, "AddIcons",
-                                        gs_plugin_appstream_add_icons_cb,
-                                        plugin, NULL);
+       fixup1 = xb_builder_fixup_new ("AddIcons",
+                                      gs_plugin_appstream_add_icons_cb,
+                                      plugin, NULL);
+       xb_builder_fixup_set_max_depth (fixup1, 2);
+       xb_builder_source_add_fixup (source, fixup1);
 
        /* fix up any legacy installed files */
-       xb_builder_source_add_node_func (source, "AppStreamUpgrade",
-                                        gs_plugin_appstream_upgrade_cb,
-                                        plugin, NULL);
+       fixup2 = xb_builder_fixup_new ("AppStreamUpgrade",
+                                      gs_plugin_appstream_upgrade_cb,
+                                      plugin, NULL);
+       xb_builder_fixup_set_max_depth (fixup2, 3);
+       xb_builder_source_add_fixup (source, fixup2);
 
        /* add the origin as a search keyword for small repos */
-       xb_builder_source_add_node_func (source, "AddOriginKeyword",
-                                        gs_plugin_appstream_add_origin_keyword_cb,
-                                        plugin, NULL);
+       fixup3 = xb_builder_fixup_new ("AddOriginKeyword",
+                                      gs_plugin_appstream_add_origin_keyword_cb,
+                                      plugin, NULL);
+       xb_builder_fixup_set_max_depth (fixup3, 1);
+       xb_builder_source_add_fixup (source, fixup3);
 
        /* success */
        xb_builder_import_source (builder, source);
@@ -431,17 +446,23 @@ gs_plugin_appstream_check_silo (GsPlugin *plugin,
        /* only when in self test */
        test_xml = g_getenv ("GS_SELF_TEST_APPSTREAM_XML");
        if (test_xml != NULL) {
+               g_autoptr(XbBuilderFixup) fixup1 = NULL;
+               g_autoptr(XbBuilderFixup) fixup2 = NULL;
                g_autoptr(XbBuilderSource) source = xb_builder_source_new ();
                if (!xb_builder_source_load_xml (source, test_xml,
                                                 XB_BUILDER_SOURCE_FLAG_NONE,
                                                 error))
                        return FALSE;
-               xb_builder_source_add_node_func (source, "AddOriginKeywords",
-                                                gs_plugin_appstream_add_origin_keyword_cb,
-                                                plugin, NULL);
-               xb_builder_source_add_node_func (source, "AddIcons",
-                                                gs_plugin_appstream_add_icons_cb,
-                                                plugin, NULL);
+               fixup1 = xb_builder_fixup_new ("AddOriginKeywords",
+                                              gs_plugin_appstream_add_origin_keyword_cb,
+                                              plugin, NULL);
+               xb_builder_fixup_set_max_depth (fixup1, 1);
+               xb_builder_source_add_fixup (source, fixup1);
+               fixup2 = xb_builder_fixup_new ("AddIcons",
+                                              gs_plugin_appstream_add_icons_cb,
+                                              plugin, NULL);
+               xb_builder_fixup_set_max_depth (fixup2, 2);
+               xb_builder_source_add_fixup (source, fixup2);
                xb_builder_import_source (builder, source);
        } else {
                /* add search paths */
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 4de6ca2f..28c2b899 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -204,7 +204,7 @@ gs_plugin_flatpak_changed_cb (GFileMonitor *monitor,
 }
 
 static gboolean
-gs_flatpak_add_flatpak_keyword_cb (XbBuilderSource *self,
+gs_flatpak_add_flatpak_keyword_cb (XbBuilderFixup *self,
                                   XbBuilderNode *bn,
                                   gpointer user_data,
                                   GError **error)
@@ -215,7 +215,7 @@ gs_flatpak_add_flatpak_keyword_cb (XbBuilderSource *self,
 }
 
 static gboolean
-gs_flatpak_fix_id_desktop_suffix_cb (XbBuilderSource *self,
+gs_flatpak_fix_id_desktop_suffix_cb (XbBuilderFixup *self,
                                     XbBuilderNode *bn,
                                     gpointer user_data,
                                     GError **error)
@@ -240,7 +240,7 @@ gs_flatpak_fix_id_desktop_suffix_cb (XbBuilderSource *self,
 }
 
 static gboolean
-gs_flatpak_set_origin_cb (XbBuilderSource *self,
+gs_flatpak_set_origin_cb (XbBuilderFixup *self,
                          XbBuilderNode *bn,
                          gpointer user_data,
                          GError **error)
@@ -254,7 +254,7 @@ gs_flatpak_set_origin_cb (XbBuilderSource *self,
 }
 
 static gboolean
-gs_flatpak_filter_default_branch_cb (XbBuilderSource *self,
+gs_flatpak_filter_default_branch_cb (XbBuilderFixup *self,
                                     XbBuilderNode *bn,
                                     gpointer user_data,
                                     GError **error)
@@ -280,7 +280,7 @@ gs_flatpak_filter_default_branch_cb (XbBuilderSource *self,
 }
 
 static gboolean
-gs_flatpak_filter_noenumerate_cb (XbBuilderSource *self,
+gs_flatpak_filter_noenumerate_cb (XbBuilderFixup *self,
                                  XbBuilderNode *bn,
                                  gpointer user_data,
                                  GError **error)
@@ -314,6 +314,9 @@ gs_flatpak_add_apps_from_xremote (GsFlatpak *self,
        g_autoptr(GFile) appstream_dir = NULL;
        g_autoptr(GFile) file_xml = NULL;
        g_autoptr(GSettings) settings = NULL;
+       g_autoptr(XbBuilderFixup) fixup1 = NULL;
+       g_autoptr(XbBuilderFixup) fixup2 = NULL;
+       g_autoptr(XbBuilderFixup) fixup3 = NULL;
        g_autoptr(XbBuilderNode) info = NULL;
        g_autoptr(XbBuilderSource) source = xb_builder_source_new ();
 
@@ -345,19 +348,25 @@ gs_flatpak_add_apps_from_xremote (GsFlatpak *self,
                return FALSE;
 
        /* add the flatpak search keyword */
-       xb_builder_source_add_node_func (source, "AddKeywordFlatpak",
-                                        gs_flatpak_add_flatpak_keyword_cb,
-                                        self, NULL);
+       fixup1 = xb_builder_fixup_new ("AddKeywordFlatpak",
+                                      gs_flatpak_add_flatpak_keyword_cb,
+                                      self, NULL);
+       xb_builder_fixup_set_max_depth (fixup1, 2);
+       xb_builder_source_add_fixup (source, fixup1);
 
        /* ensure the <id> matches the flatpak ref ID  */
-       xb_builder_source_add_node_func (source, "FixIdDesktopSuffix",
-                                        gs_flatpak_fix_id_desktop_suffix_cb,
-                                        self, NULL);
+       fixup2 = xb_builder_fixup_new ("FixIdDesktopSuffix",
+                                      gs_flatpak_fix_id_desktop_suffix_cb,
+                                      self, NULL);
+       xb_builder_fixup_set_max_depth (fixup2, 2);
+       xb_builder_source_add_fixup (source, fixup2);
 
        /* override the *AppStream* origin */
-       xb_builder_source_add_node_func (source, "SetOrigin",
-                                        gs_flatpak_set_origin_cb,
-                                        xremote, NULL);
+       fixup3 = xb_builder_fixup_new ("SetOrigin",
+                                      gs_flatpak_set_origin_cb,
+                                      xremote, NULL);
+       xb_builder_fixup_set_max_depth (fixup3, 1);
+       xb_builder_source_add_fixup (source, fixup3);
 
        /* add metadata */
        icon_prefix = g_build_filename (appstream_dir_fn, "icons", NULL);
@@ -369,22 +378,28 @@ gs_flatpak_add_apps_from_xremote (GsFlatpak *self,
        /* only add the specific app for noenumerate=true */
        if (flatpak_remote_get_noenumerate (xremote)) {
                g_autofree gchar *tmp = NULL;
+               g_autoptr(XbBuilderFixup) fixup = NULL;
                tmp = g_strdup (flatpak_remote_get_name (xremote));
                g_strdelimit (tmp, "-", '\0');
-               xb_builder_source_add_node_func (source, "FilterNoEnumerate",
-                                                gs_flatpak_filter_noenumerate_cb,
-                                                g_strdup (tmp),
-                                                g_free);
+               fixup = xb_builder_fixup_new ("FilterNoEnumerate",
+                                             gs_flatpak_filter_noenumerate_cb,
+                                             g_strdup (tmp),
+                                             g_free);
+               xb_builder_fixup_set_max_depth (fixup, 2);
+               xb_builder_source_add_fixup (source, fixup);
        }
 
        /* do we want to filter to the default branch */
        settings = g_settings_new ("org.gnome.software");
        if (g_settings_get_boolean (settings, "filter-default-branch") &&
            flatpak_remote_get_default_branch (xremote) != NULL) {
-               xb_builder_source_add_node_func (source, "FilterDefaultbranch",
-                                                gs_flatpak_filter_default_branch_cb,
-                                                flatpak_remote_get_default_branch (xremote),
-                                                g_free);
+               g_autoptr(XbBuilderFixup) fixup = NULL;
+               fixup = xb_builder_fixup_new ("FilterDefaultbranch",
+                                             gs_flatpak_filter_default_branch_cb,
+                                             flatpak_remote_get_default_branch (xremote),
+                                             g_free);
+               xb_builder_fixup_set_max_depth (fixup, 2);
+               xb_builder_source_add_fixup (source, fixup);
        }
 
        /* success */
@@ -421,6 +436,7 @@ gs_flatpak_load_desktop_fn (GsFlatpak *self,
        g_autoptr(GFile) file = g_file_new_for_path (filename);
        g_autoptr(XbBuilderNode) info = NULL;
        g_autoptr(XbBuilderSource) source = xb_builder_source_new ();
+       g_autoptr(XbBuilderFixup) fixup = NULL;
 
        /* add support for desktop files */
        xb_builder_source_add_converter (source,
@@ -429,9 +445,11 @@ gs_flatpak_load_desktop_fn (GsFlatpak *self,
                                         NULL, NULL);
 
        /* add the flatpak search keyword */
-       xb_builder_source_add_node_func (source, "AddKeywordFlatpak",
-                                        gs_flatpak_add_flatpak_keyword_cb,
-                                        self, NULL);
+       fixup = xb_builder_fixup_new ("AddKeywordFlatpak",
+                                     gs_flatpak_add_flatpak_keyword_cb,
+                                     self, NULL);
+       xb_builder_fixup_set_max_depth (fixup, 2);
+       xb_builder_source_add_fixup (source, fixup);
 
        /* set the component metadata */
        info = xb_builder_node_insert (NULL, "info", NULL);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]