Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit b6d0ce1

Browse files
committed
[signals] Minor performance optimization
- Minor performance optimization to speed up signal handlers; substitutes call_user_func for call_user_func_array for finite numbers of arguments.
1 parent 756e79e commit b6d0ce1

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/SignalHandler.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,24 @@ public function getCallback()
117117
public function call(array $args = array())
118118
{
119119
$callback = $this->getCallback();
120-
return call_user_func_array($callback, $args);
120+
121+
// Following is a performance optimization hack. call_user_func() is up
122+
// to 6x faster than call_user_func_array(), and since signal handlers
123+
// will be called potentially dozens to hundreds of times in an
124+
// application, this optimization makes sense.
125+
//
126+
// We can potentially expand the number of case statements if we find
127+
// many instances where we're using more arguments.
128+
switch (count($args)) {
129+
case 1:
130+
return call_user_func($callback, $args[0]);
131+
case 2:
132+
return call_user_func($callback, $args[0], $args[1]);
133+
case 3:
134+
return call_user_func($callback, $args[0], $args[1], $args[2]);
135+
default:
136+
return call_user_func_array($callback, $args);
137+
}
121138
}
122139

123140
/**

0 commit comments

Comments
 (0)