[php-src] PR #14561: zend_compile: Add support for `%d` to `sprintf()` optimization

From: Date: Thu, 13 Jun 2024 11:50:03 +0000
Subject: [php-src] PR #14561: zend_compile: Add support for `%d` to `sprintf()` optimization
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-26662@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/14561 Author: TimWolla This is a follow-up for #14546 that I announced in https://github.com/php/php-src/pull/14546#issuecomment-2163160570 ---------- This extends the existing sprintf() optimization by support for the %d placeholder, which effectively equivalent to an (int) cast followed by a (string) cast. For a synthetic test using: ```php <?php $a = 'foo'; $b = 42; for ($i = 0; $i < 100_000_000; $i++) { sprintf("%s-%d", $a, $b); } ``` This optimization yields a 1.3× performance improvement: $ hyperfine 'sapi/cli/php -d zend_extension=php-src/modules/opcache.so -d opcache.enable_cli=1 test.php' \ '/tmp/unoptimized -d zend_extension=php-src/modules/opcache.so -d opcache.enable_cli=1 test.php' Benchmark 1: sapi/cli/php -d zend_extension=php-src/modules/opcache.so -d opcache.enable_cli=1 test.php Time (mean ± σ): 3.296 s ± 0.094 s [User: 3.287 s, System: 0.005 s] Range (min … max): 3.213 s … 3.527 s 10 runs Benchmark 2: /tmp/unoptimized -d zend_extension=php-src/modules/opcache.so -d opcache.enable_cli=1 test.php Time (mean ± σ): 4.300 s ± 0.025 s [User: 4.290 s, System: 0.007 s] Range (min … max): 4.266 s … 4.334 s 10 runs Summary sapi/cli/php -d zend_extension=php-src/modules/opcache.so -d opcache.enable_cli=1 test.php ran 1.30 ± 0.04 times faster than /tmp/unoptimized -d zend_extension=php-src/modules/opcache.so -d opcache.enable_cli=1 test.php

« previous php.git-pulls (#26662) next »