I am currently looking for different performance bottlenecks in the Drupal admin pages using xdebug, and found one more thing that could be optimized.
In theme.inc, function _theme_process_registry, called a lot of times by _theme_build_registry, I count around 80.000 calls to function_exists() looking for hook implementations with '_preprocess_' in the name, while there are only around 2.000 functions defined (using get_defined_functions). It's not a big deal, but it adds up to overall execution time (around 150ms on my machine) for those requests which rebuild the theme registry.
I imagine we could improve this (and maybe other hook scans as well) with the following approach (pseudo-php) inside _theme_build_registry:
<?php
$implementations_by_prefix = array();
$implementations_by_hook = array();
$candidates = get_defined_functions();
foreach ($candidates as $candidate) {
$explode = explode('_preprocess_', $candidate);
if (count($explode) == 2) {
list($prefix, $hook) = $explode;
$implementations_by_hook[$hook][] = $candidate;
$implementations_by_prefix[$prefix][] = $candidate;
} else if (count($explode) > 2) {
// TODO: kill the author of this function..
}
}
// TODO: do something with the functions found this way..
?>
This is not yet thought through to the end, but maybe it could be a useful approach?