_theme_process_registry
called a lot of times by _theme_build_registry in theme.inc line 399 (one time for each module implementation of hook_theme)
called by _theme_load_registry in theme.inc line 225
on the admin modules page.

The function is especially slow for imagecache_theme, system_theme and some others.
Each time it calls tons of function_exists (wincachegrind says 182.000 calls to function_exists in total, and most of them are called in line 330 or 334 of theme.inc, in _theme_process_registry)

The problem seems to be the
foreach ($prefixes as $prefix)
in _theme_process_registry.

The number of possible prefixes and suffixes for preprocess functions can be exponentially high.

Solution:
- do one call to get_defined_functions, for the entire _theme_build_registry.
- check all the returned function names if they have "_preprocess_" in the name, or end with "_preprocess".
- use these results to build the registry.

I think this should be a lot faster.

Comments

mattyoung’s picture

.

donquixote’s picture

StatusFileSize
new1.14 KB

Does this help?

A function that uses get_defined_functions() to find all possible hook implementations at one go.

The idea is that functions look like this:

$function = $module . '_' . $hook;  // or
$function = $module . '_' . $hook . '_' . $suffix;

The result is sorted like this:

$result[$hook][$module][0] = NULL;
$result[$hook][$module][] = $suffix;
donquixote’s picture

Slightly different implementation, this time sorted by

// with $find_suffixes enabled
$result[$hook][''][] = $module;
$result[$hook][$suffix][] = $module;

// with $find_suffixes disabled
$result[$hook][] = $module

The function is $module . '_' . $hook . $suffix, but $suffix always begins with a '_'.

donquixote’s picture

StatusFileSize
new2.06 KB

And yet another one, this time specialized on the use in _theme_process_registry: It only scans for one specific hook (this time, everything with '_preprocess_')

donquixote’s picture

Title: _theme_process_registry slowed down by checking an exponential number of prefix combinations. » speed up _theme_process_registry(): get_defined_functions() instead of function_exists()

change the title

donquixote’s picture

Status: Active » Closed (duplicate)

I duplicated myself, see
#519940: Performance: optimize building theme registry by using get_defined_functions() instead of function_exists()

Still, the code I uploaded in this issue makes a lot of sense, I will upload it again in the older issue.

fuzzy76’s picture

Issue summary: View changes

Trying to do CPR on D6 site until it can be replaced... How was these functions supposed to be used?