Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joelpittet/f22596ca587ffe009fb5 to your computer and use it in GitHub Desktop.
Save joelpittet/f22596ca587ffe009fb5 to your computer and use it in GitHub Desktop.
module_invoke_all performance
diff --git a/includes/module.inc b/includes/module.inc
index 06bc979..3d2e468 100644
--- a/includes/module.inc
+++ b/includes/module.inc
@@ -892,12 +892,14 @@ function module_invoke($module, $hook) {
* @see drupal_alter()
*/
function module_invoke_all($hook) {
+ $times = [];
$args = func_get_args();
// Remove $hook from the arguments.
unset($args[0]);
$return = array();
foreach (module_implements($hook) as $module) {
$function = $module . '_' . $hook;
+ $startTime = microtime(true);
if (function_exists($function)) {
$result = call_user_func_array($function, $args);
if (isset($result) && is_array($result)) {
@@ -907,8 +909,10 @@ function module_invoke_all($hook) {
$return[] = $result;
}
}
+ $times[$function] = microtime(true) - $startTime;
}
+ arsort($times);
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment