]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
config: Speed up ACO & sorcery initialization
authorSean Bright <sean.bright@gmail.com>
Fri, 1 Dec 2017 14:29:43 +0000 (09:29 -0500)
committerSean Bright <sean.bright@gmail.com>
Fri, 1 Dec 2017 14:29:43 +0000 (09:29 -0500)
When starting Asterisk in the foreground, there is a perceptible delay
when loading modules that use the ACO and sorcery config frameworks.
For example, a lightly configured res_pjsip took 853ms to load on my
VM.

I tracked down the slowness to the XPath queries used to associate the
relevant documentation with the config options. One improvement was
adding a call to xmlXPathOrderDocElems after loading an XML document.
From the libxml2 docs:

  Call this routine to speed up XPath computation on static documents.

The second change was to remove recursive descent and wildcard
operators from the XPath queries. After these changes, res_pjsip takes
85ms to load on my VM and there is no longer a perceptible delay when
starting Asterisk in the foreground.

Change-Id: I45d457f1580e26bf5a2b0dab16e8e9ae46dcbd82

main/config_options.c
main/xml.c

index 484eaf6e4961c2883e337e58860f107693d153aa..f52d3c410d7ebf0cd428d69729a626a08194ad48 100644 (file)
@@ -1000,11 +1000,11 @@ static int xmldoc_update_config_type(const char *module, const char *name, const
 
        /* If we already have a syntax element, bail. This isn't an error, since we may unload a module which
         * has updated the docs and then load it again. */
-       if ((results = ast_xmldoc_query("//configInfo[@name='%s']/*/configObject[@name='%s']/syntax", module, name))) {
+       if ((results = ast_xmldoc_query("/docs/configInfo[@name='%s']/configFile/configObject[@name='%s']/syntax", module, name))) {
                return 0;
        }
 
-       if (!(results = ast_xmldoc_query("//configInfo[@name='%s']/*/configObject[@name='%s']", module, name))) {
+       if (!(results = ast_xmldoc_query("/docs/configInfo[@name='%s']/configFile/configObject[@name='%s']", module, name))) {
                ast_log(LOG_WARNING, "Cannot update type '%s' in module '%s' because it has no existing documentation!\n", name, module);
                return XMLDOC_STRICT ? -1 : 0;
        }
@@ -1070,7 +1070,7 @@ static int xmldoc_update_config_option(struct aco_type **types, const char *modu
                return XMLDOC_STRICT ? -1 : 0;
        }
 
-       if (!(results = ast_xmldoc_query("//configInfo[@name='%s']/*/configObject[@name='%s']/configOption[@name='%s']", module, object_name, name))) {
+       if (!(results = ast_xmldoc_query("/docs/configInfo[@name='%s']/configFile/configObject[@name='%s']/configOption[@name='%s']", module, object_name, name))) {
                ast_log(LOG_WARNING, "Could not find option '%s' with type '%s' in module '%s'\n", name, object_name, module);
                return XMLDOC_STRICT ? -1 : 0;
        }
index dee2497113746f92a426e2696cbef9daf27f59ff..bd82b5cbf6070e6b02715c857ac5a76378bed7e6 100644 (file)
@@ -98,6 +98,9 @@ struct ast_xml_doc *ast_xml_open(char *filename)
        ast_log(LOG_NOTICE, "XSLT support not found. XML documentation may be incomplete.\n");
 #endif /* HAVE_LIBXSLT */
 
+       /* Optimize for XPath */
+       xmlXPathOrderDocElems(doc);
+
        return (struct ast_xml_doc *) doc;
 }