Created
March 6, 2015 17:05
-
-
Save joelpittet/f22596ca587ffe009fb5 to your computer and use it in GitHub Desktop.
module_invoke_all performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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