Skip to content

Commit 6944fde

Browse files
committed
[Messenger] Narrow HandleMessageMiddleware::callHandler()’s $handler parameter to \Closure
Since the previous commit this is guaranteed to be a `\Closure`. A microbenchmark using: <?php function closure_(\Closure $f) { $f('abc'); } function callable_(callable $f) { $f('abc'); } for ($i = 0; $i < 10000000; $i++) { callable_(strrev(...)); } Indicates that using `\Closure` as the parameter type is roughly 10% faster: Benchmark 1: php callable.php Time (mean ± σ): 708.4 ms ± 5.8 ms [User: 696.4 ms, System: 11.5 ms] Range (min … max): 699.5 ms … 715.7 ms 10 runs Benchmark 2: php closure.php Time (mean ± σ): 647.1 ms ± 21.0 ms [User: 633.2 ms, System: 13.2 ms] Range (min … max): 626.7 ms … 683.7 ms 10 runs Summary php closure.php ran 1.09 ± 0.04 times faster than php callable.php
1 parent bd414a1 commit 6944fde

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Symfony/Component/Messenger/Middleware/HandleMessageMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private function messageHasAlreadyBeenHandled(Envelope $envelope, HandlerDescrip
139139
return false;
140140
}
141141

142-
private function callHandler(callable $handler, object $message, ?Acknowledger $ack, ?HandlerArgumentsStamp $handlerArgumentsStamp): mixed
142+
private function callHandler(\Closure $handler, object $message, ?Acknowledger $ack, ?HandlerArgumentsStamp $handlerArgumentsStamp): mixed
143143
{
144144
$arguments = [$message];
145145
if (null !== $ack) {

0 commit comments

Comments
 (0)