[php-src] PR #22231: perf: move EG() and CG() in ZTS builds into __thread storage

From: Date: Fri, 05 Jun 2026 13:00:32 +0000
Subject: [php-src] PR #22231: perf: move EG() and CG() in ZTS builds into __thread storage
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-36305@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/22231 Author: henderkes So, I was chasing what caused [the much higher instruction count on aarch64 for clang vs gcc](https://github.com/shivammathur/homebrew-php/issues/5161#issuecomment-4608440602) and while figuring that out, got side tracked to figuring out that ZTS builds also have a ton of extra instructions compared to NTS builds. Turned out it was mostly just from constantly accessing executor and compiler globals when running phpstan. Each access became pseudo assembly: ```asm mrs _tsrm_ls_cache add cache offset low bits add cache offset high bits load relative base address load accessed global ``` Here we're slashing one extra load and one add by moving EG and CG onto actual thread storage. Benchmarks are using phpstan on full laravel codebase (full symfony codebase showed the same, but I added the LE optimization after and don't want to rerun 6 hours of benchmarks) and phoronix-test-suite phpbench. aarch64: - ~80% fewer extra instructions - Ampere A1 cloud machine, ~0.15% variance in wall clock between runs <table><thead><tr><th>build</th><th>PHPStan cyc</th><th>instr</th><th>wall</th><th>phpbench</th><th>phpbench JIT</th></tr></thead><tbody><tr><td>gcc-nts</td><td>90.67B</td><td>108.22B</td><td>32.0s</td><td>715719</td><td>116467 1</td></tr><tr><td>gcc-zts</td><td>94.44B</td><td>116.28B</td><td>33.2s</td><td>662475</td><td>1111162</td></tr><tr><t d>d>gcc-zts-patch</td><td>91.61B</td><td>109.66B</td><td>32.3s</td><td>704490</td><td>1146721</td></tr><tr><td>clang-nts </td><td>95.20B</td><td>113.29B</td><td>33.4s</td><td>709077</td><td>1118672</td></tr><tr><td>clang-zts</td><td>97.92B </td><td>120.82B</td><td>34.4s</td><td>665074</td><td>1069905</td></tr><tr><td>clang-zts-patch</td><td>93.40B</td><td> 114.72B</td><td>33.1s</td><td>696929</td><td>1101997</td></tr></tbody></table> x86_64: - ~35% fewer extra instructions - no cycle count on x86_64 because lack of hardware counter support in WSL - i7 12650h with locked cpu frequency, take the wall times with a grain of salt now as the minified html I pasted at the beginning20:00Claude responded: <table><thead><tr><th>build</th><th>PHPStan cyc</th><th>instr</th><th>wall</th><th>phpbench</th><th>phpbench JIT</th></tr></thead><tbody><tr><td>gcc-nts</td><t…<table><thead><tr><th>build</th><th>PHPStan cyc</th><th>instr</th><th>wall</th><th>phpbench</th><th>phpbench JIT</th></tr></thead><tbody><tr><td>gcc-nts</td><td>n/a</td><td>11.01B</td><td>113.91s</td><td>1065687</td><td>1793058</td></tr><tr><td>gcc-zts</td><td>n/a</td><td>11.23B</td><td>115.47s</td><td>1033552</td><td>1767360</td></tr><tr><td>gcc-zts-patch</td><td>n/a</td><td>11.15B</td><td>116.34s</td><td>1005077</td><td>1713823</td></tr><tr><td>clang-nts</td><td>n/a</td><td>11.38B</td><td>112.92s</td><td>1125988</td><td>1795096</td></tr><tr><td>clang-zts</td><td>n/a</td><td>11.64B</td><td>114.67s</td><td>1087697</td><td>1757513</td></tr><tr><td>clang-zts-patch</td><td>n/a</td><td>11..53B</td><td>112.22s</td><td>1145744</td><td>1793294</td></tr></tbody></table> ### LLM disclosure claude - adjusted the JIT - transformed the raw bash results into these (hopefully beautiful) html tables

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