Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
preg_grep in _bootstrap_process_theme_registry_suggestions function is taking time exponentially to the number of defined functions and enabled themes respectively.
foreach ($themes as $theme) {
foreach ($registry as $hook => $info) {
......
foreach ($variable_process_phases as $phase_key => $phase) {
if ($matches = preg_grep('/^' . $theme . '_' . $phase . '_' . $pattern . '/', $functions['user'])) {
I have attached a performance profile that have 6000~ functions defined and 4 theme enabled or used basethems
Comment | File | Size | Author |
---|---|---|---|
#5 | preg_grep_in-2416485-4.patch | 2.84 KB | markhalliwell |
Comments
Comment #1
mkhamash CreditAttribution: mkhamash commentedI just have re-order who we order the search for functions matching needed patterns, it reduced the time spent on perg_grep from 3sec to 0.05 sec.
Comment #2
markhalliwellHm, interesting. I agree this could be done better. I am less concerned because in all reality, this is only a one time performance hit as the registry is cached immediately after it's built.
I'm now following #2339447: Improve theme registry build performance by 85% and will be keeping tabs on it. I'll go ahead bump the priority, but mark as postponed until that issue solidifies more. I would like to mimic whatever is done in that issue as much as possible here.
Comment #3
markhalliwellComment #5
markhalliwellThat issue has been committed to 8.x and is now just waiting for a backport to 7.x.
Here is a patch that mimics that implementation. I will go ahead and commit it.
FWIW, this entire function will not be needed once #939462: Specific preprocess functions for theme hook suggestions are not invoked makes it in. That could be a while before that happens though.
Comment #8
donquixote CreditAttribution: donquixote as a volunteer commentedIs there any recent version of core where
function drupal_group_functions_by_prefix()
exists?I see it was added here, https://cgit.drupalcode.org/drupal/commit/?id=db8fda5c7658d2d89953c21d57...
and removed here, https://cgit.drupalcode.org/drupal/commit/?id=5072353
And even if is present in some core versions, what do we gain with this
if (function_exists(..))
conditional function declaration?Why not have a
function _bootstra_group_functions_by_prefix()
instead?I don't see any static cache in there, so let bootstrap have its own version with _bootstrap_ prefix.