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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mkhamash’s picture

I 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.

markhalliwell’s picture

Priority: Normal » Major
Status: Active » Postponed

Hm, 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.

markhalliwell’s picture

Category: Feature request » Bug report

  • markcarver committed f020f3b on 7.x-3.x
    Issue #2416485 by markcarver, mkhamash: preg_grep in...
markhalliwell’s picture

That 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.

  • markcarver committed 2967051 on 8.x-3.x
    Issue #2416485 by markcarver, mkhamash: preg_grep in...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

donquixote’s picture

Is 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.