Skip to content
Snippets Groups Projects
  • Sean Bright's avatar
    d9fdeae6
    config: Speed up config template lookup · d9fdeae6
    Sean Bright authored
    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
    d9fdeae6
    History
    config: Speed up config template lookup
    Sean Bright authored
    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