Related posts
- BOLT, PGO or both for PHP on a Xeon
I built PHP 8.5.13 four ways on the Xeon test host: plain, with BOLT, with clang PGO, and with both. BOLT and PGO each give about +7 % on uncached XenForo pages, but PGO on top of the BOLT build my setup script already ships adds only -1 to +2.4 %, so it stays out where BOLT runs.
- PGO where BOLT cannot run: PHP 8.6 on an AMD EPYC (Zen 1)
My setup script optimises PHP's code layout with BOLT, but BOLT needs branch records that older AMD CPUs such as Zen 1 don't have, so on those machines PHP gets no layout optimisation at all. Profile-guided optimisation trained on XenForo traffic filled the gap: +6 to +9 % requests per second on an EPYC 7401P, with one catch for the PHP CLI.
- Why my from-source PHP was slower, and the one-line answer: ICU
A from-source php-fpm executed 9 % fewer instructions per page than a clang build using Sury's extensions, yet ran 1-2 % slower. The cause was ICU: the intl extension made the binary 102 MB and multiplied data-TLB misses by 4.5. Without it, the merged build is the fastest: +11 % on logged-in XenForo pages.
Earlier today I wrote up PGO where BOLT cannot run: on an AMD EPYC 7401P (Zen 1), which has no last branch records (LBR), profile-guided optimisation made PHP 8.6 +6 to +9 % faster on uncached XenForo pages. That post ended with two caveats. About half the training requests hit the pages the benchmark measured, and PHP without the JIT got 10.3 % slower on
bench.php, which matters for the CLI.The follow-up has finished. It fixes both caveats and adds the one kind of BOLT this CPU allows, so there are four arms instead of two.
Short version: PGO alone was the fastest build on every tier, +6.1 to +8.4 %, and won all 20 tier/round comparisons. BOLT from plain samples gave +4.3 to +5.0 % on its own, but on top of PGO it made things worse. The CLI regression halved but didn’t go away, so the plan is to build the CLI without the profile.
The four builds#
All four are PHP 8.6.0 with the same configure line, 28 extensions, library versions and flags as the PHP my setup script builds for that CPU (clang, ThinLTO,
-march=native, mimalloc, tracing JIT).bolt=nolbrcyclessamples, no branch records-fprofile-useThe BOLT arms need a word. Normally BOLT reads branch history from LBR, which Zen 1 doesn’t have. It can also work from plain samples of where the CPU was (
perf2bolt -nl), which tell it which code is hot but not which way branches went. It’s coarser data, but it runs anywhere. Everything after the profile used the samellvm-boltflags the script uses on Intel.What changed from the first run#
phpranZend/bench.php,micro_bench.phpand XenForo’s owncmd.phpcommands (xf:run-jobs,list,xf-addon:list) with OPcache off. Those counts were merged into the same profile at a weight that made them about 25 % of the total. At equal weight they would have been 3 %, too little to warm anything.The merged profile looks different from the first run’s. The hottest functions are now VM handlers (
ZEND_PRE_INC,IS_SMALLER_JMPNZ,ASSIGN), then the same string and allocator helpers as before:php_strtr_array,_efree,_emalloc,zend_hash_find. It touched 4,307 of 17,113 functions.How it was measured#
Same method as the first run. The EPYC is someone else’s shared development server, so nothing was installed system-wide. Everything ran inside one temporary directory with a private copy of the stack: MariaDB, Valkey, php-fpm and nginx on local sockets, a XenForo forum with seeded data, 12 static PHP-FPM workers, and
wrkwith 48 connections for 10 s per tier. The stack and the load generator were pinned to the upper half of the logical CPUs, and I watched the lower half for the neighbours’ load.Five rounds, with the order of the four arms rotated each round. Medians, with the slowest and fastest round in brackets. I couldn’t pin the CPU clock on a machine I don’t own, so single rounds are noisy. The lower half was at most 2.3 % busy during any tier (median 0.1 %), and no request returned anything but 2xx.
Afterwards I deleted the directory and ran the same before/after audit as last time. The machine was unchanged apart from two traces of the run. While
perfwas sampling, the kernel lowered its own perf sample-rate limit, as it does when a sampling interrupt takes too long; I restored the original value. And a configure probe that crashes on purpose during the PHP build added three lines to the system’s crash-reporter log (no crash file was written, and the first run left the same kind of line). I left that log as it was.The numbers#
Requests per second on the uncached tiers, the ones that run PHP. Percentages compare with plain.
Median p99 latency fell for all three variants:
Round by round, PGO beat plain in all 20 tier/round pairs, from +2.6 % to +11.6 %. Round 5 had plain’s lowest numbers, as in the first run, so its deltas are inflated for every arm, but the medians don’t depend on it.
The PGO numbers barely moved from the first run (+6.2 to +9.1 % then, +6.1 to +8.4 % now), even with the measured pages taken out of training. So the gain wasn’t the profile fitting the test.
BOLT without LBR: useful alone, harmful on top#
Sample-based BOLT on the plain build was worth +4.3 to +5.0 %, about 60 to 80 % of what PGO gave on the same tier. Its profile covered 1,638 of 38,011 functions and changed the block layout of 1,337 of them.
On top of PGO it lost 1.9 to 4.4 % against PGO alone, on every tier’s median. That fits how the two work. PGO has exact edge counts from an instrumented build and has already laid the code out from them. Sample-based BOLT then lays it out again from data that knows which code is hot but not which way each branch went. It undoes good decisions with worse information.
About 20 % of the samples were also dropped in both BOLT steps, because
perf2boltcouldn’t find the base address of one mapping per process, most likely the region PHP’s OPcache moves onto huge pages. The script’s own BOLT step samples with huge pages on, so it would lose the same share. That doesn’t change the ranking here, since BOLT lost on top of PGO either way.The CLI: halved, not fixed#
PHP’s own CPU benchmarks with
php -n, pinned to one CPU, three runs each, median in seconds. BOLT only rewritesphp-fpm, so the CLI binaries of the BOLT arms are byte-identical to their bases and aren’t shown.bench.php, no JITmicro_bench.php, no JITbench.php, JITmicro_bench.php, JITWith the JIT on, everything is within about 2 %, the run-to-run noise the repeated (byte-identical) binaries showed. Without the JIT, training the CLI halved the regression but didn’t remove it. And this flatters PGO a little, because
bench.phpandmicro_bench.phpwere part of the training. A cron job running XenForo code it never saw would probably do no better.My rule for a default is at least 2 % faster somewhere and slower nowhere. The CLI is still slower, so it doesn’t get the profile.
What I didn’t measure#
bench.phpstands in for cron jobs and imports. I didn’t timexf:run-jobsitself.What it means for the script#
Across both machines, the picture is now consistent:
That’s the design of default-on PGO for the next release. The numbers for this run sit next to the first AMD run and the Intel runs in
tests/stress-site/RESULTS.mdin ubuntu-setup-script.