[php-src] Issue #20543: Pipe operators are twice slower than their equivalents

From: Date: Thu, 20 Nov 2025 19:25:24 +0000
Subject: [php-src] Issue #20543: Pipe operators are twice slower than their equivalents
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-251262@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/20543 Author: kamil-tekiela ### Description The following code: ```php <?php $arr = [ new Widget(tags: ['a', 'b', 'c']), new Widget(tags: ['c', 'd', 'e']), new Widget(tags: ['x', 'y', 'a']), ]; class Widget { public function __construct( public array $tags = [], ) {} } class Benchmark { private $startTime; private $endTime; public function start() { $this->startTime = hrtime(true); } public function end() { $this->endTime = hrtime(true); } public function getElapsedTime() { return ($this->endTime - $this->startTime)/1_000_000_000; } } // Example usage $benchmark = new Benchmark(); $trimClosure = trim(...); $strtolowerClosure = strtolower(...); // ==================================== $benchmark->start(); // Code to benchmark for ($i = 0; $i < 1000000; $i++) { $title = ' PHP 8.5 Released '; $slug1 = $title |> $trimClosure |> $strtolowerClosure; // string(15) "php-85-released" } $benchmark->end(); echo "Elapsed time: " . $benchmark->getElapsedTime() . " seconds\n"; $benchmark->start(); // Code to benchmark for ($i = 0; $i < 1000000; $i++) { $title = ' PHP 8.5 Released '; $slug2 = $strtolowerClosure( $trimClosure($title) ); // string(15) "php-85-released" } $benchmark->end(); echo "Elapsed time: " . $benchmark->getElapsedTime() . " seconds\n"; var_dump($slug1 === $slug2); ``` Resulted in this output: ``` Elapsed time: 0.09693445 seconds Elapsed time: 0.059030439 seconds bool(true) ``` But I expected this output instead: ``` Elapsed time: 0.059030439 seconds Elapsed time: 0.059030439 seconds bool(true) ``` I thought that the slowdown came from preparing the closures in the PHP manual, but I am pretty sure I have elemited all extra overhead from the benchmark above and the timings haven't changed. It seems that the pipe operator adds a lot of overhead itself. ### PHP Version ```plain PHP 8.5.0 as tested on https://3v4l.org/uu0Q5#v8.5.0 ``` ### Operating System _No response_

« previous php.bugs (#251262) next »