[Asterisk-code-review] config: Speed up ACO & sorcery initialization (asterisk[15])

Joshua Colp asteriskteam at digium.com
Mon Dec 4 08:00:31 CST 2017


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/7405 )

Change subject: config: Speed up ACO & sorcery initialization
......................................................................

config: Speed up ACO & sorcery initialization

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
---
M main/config_options.c
M main/xml.c
2 files changed, 6 insertions(+), 3 deletions(-)

Approvals:
  George Joseph: Looks good to me, but someone else must approve
  Corey Farrell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Approved for Submit



diff --git a/main/config_options.c b/main/config_options.c
index 3c0959e..a9a145b 100644
--- a/main/config_options.c
+++ b/main/config_options.c
@@ -998,11 +998,11 @@
 
 	/* 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;
 	}
@@ -1068,7 +1068,7 @@
 		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;
 	}
diff --git a/main/xml.c b/main/xml.c
index d32a8c5..d476c1d 100644
--- a/main/xml.c
+++ b/main/xml.c
@@ -96,6 +96,9 @@
 	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;
 }
 

-- 
To view, visit https://gerrit.asterisk.org/7405
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: I45d457f1580e26bf5a2b0dab16e8e9ae46dcbd82
Gerrit-Change-Number: 7405
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171204/e2a90043/attachment.html>


More information about the asterisk-code-review mailing list