[Asterisk-code-review] config: Speed up config template lookup (asterisk[master])
Joshua Colp
asteriskteam at digium.com
Mon Dec 4 08:51:12 CST 2017
Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/7410 )
Change subject: config: Speed up config template lookup
......................................................................
config: Speed up config template lookup
ast_category_get() has an (undocumented) implementation detail where it
tries to match the category name first by an explicit pointer comparison
and if that fails falls back to a normal match.
When initially building an ast_config during ast_config_load, this
pointer comparison can never succeed, but we will end up iterating all
categories twice. As the number of categories using a template
increases, this dual looping becomes quite expensive. So we pass a flag
to category_get_sep() indicating if a pointer match is even possible
before trying to do so, saving us a full pass over the list of current
categories.
In my tests, loading a file with 3 template categories and 12000
additional categories that use those 3 templates (this file configures
4000 PJSIP endpoints with AOR & Auth) takes 1.2 seconds. After this
change, that drops to 22ms.
Change-Id: I59b95f288e11eb6bb34f31ce4cc772136b275e4a
---
M main/config.c
1 file changed, 9 insertions(+), 7 deletions(-)
Approvals:
Corey Farrell: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved; Approved for Submit
diff --git a/main/config.c b/main/config.c
index 3d8dcfb..a76d087 100644
--- a/main/config.c
+++ b/main/config.c
@@ -986,13 +986,15 @@
}
static struct ast_category *category_get_sep(const struct ast_config *config,
- const char *category_name, const char *filter, char sep)
+ const char *category_name, const char *filter, char sep, char pointer_match_possible)
{
struct ast_category *cat;
- for (cat = config->root; cat; cat = cat->next) {
- if (cat->name == category_name && does_category_match(cat, category_name, filter, sep)) {
- return cat;
+ if (pointer_match_possible) {
+ for (cat = config->root; cat; cat = cat->next) {
+ if (cat->name == category_name && does_category_match(cat, category_name, filter, sep)) {
+ return cat;
+ }
}
}
@@ -1008,7 +1010,7 @@
struct ast_category *ast_category_get(const struct ast_config *config,
const char *category_name, const char *filter)
{
- return category_get_sep(config, category_name, filter, ',');
+ return category_get_sep(config, category_name, filter, ',', 1);
}
const char *ast_category_get_name(const struct ast_category *category)
@@ -1792,7 +1794,7 @@
if (cur[1] != ',') {
filter = &cur[1];
}
- *cat = category_get_sep(cfg, catname, filter, '&');
+ *cat = category_get_sep(cfg, catname, filter, '&', 0);
if (!(*cat)) {
if (newcat) {
ast_category_destroy(newcat);
@@ -1810,7 +1812,7 @@
} else {
struct ast_category *base;
- base = ast_category_get(cfg, cur, "TEMPLATES=include");
+ base = category_get_sep(cfg, cur, "TEMPLATES=include", ',', 0);
if (!base) {
if (newcat) {
ast_category_destroy(newcat);
--
To view, visit https://gerrit.asterisk.org/7410
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I59b95f288e11eb6bb34f31ce4cc772136b275e4a
Gerrit-Change-Number: 7410
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171204/0b8abba8/attachment.html>
More information about the asterisk-code-review
mailing list