_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.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | drupal_hook_scan.inc_.txt | 2.06 KB | donquixote |
| #2 | drupal_hook_scan.inc_.txt | 1.14 KB | donquixote |
Comments
Comment #1
mattyoung commented.
Comment #2
donquixote commentedDoes 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:
The result is sorted like this:
Comment #3
donquixote commentedSlightly different implementation, this time sorted by
The function is
$module . '_' . $hook . $suffix, but$suffixalways begins with a '_'.Comment #4
donquixote commentedAnd 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_')
Comment #5
donquixote commentedchange the title
Comment #6
donquixote commentedI 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.
Comment #7
fuzzy76 commentedTrying to do CPR on D6 site until it can be replaced... How was these functions supposed to be used?