ubuntips

Plain, BOLT, PGO or both on an AMD EPYC (Zen 1)

Draft posted on · 8 min read

On this page
Draft commented on Dec 2, 2026

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).

ArmWhat it adds
plain (A)nothing: what the script ships on this CPU today, recorded as bolt=nolbr
+ BOLT (A+B)the plain binary rewritten by BOLT from 60 s of ordinary cycles samples, no branch records
+ PGO (P)an instrumented build trained on XenForo and CLI work, rebuilt with -fprofile-use
+ PGO + BOLT (P+B)the PGO binary through the same sample-based BOLT step

The 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 same llvm-bolt flags the script uses on Intel.

What changed from the first run#

  • No measured page in the training set. Training used 251 other URLs: 150 random threads, every forum, 50 member profiles, and the what’s-new, members and online pages. The home page, the forum list and the benchmark thread were left out, and I checked that none matched. That removes the “profile fits the test” doubt.
  • The CLI was trained too. The instrumented php ran Zend/bench.php, micro_bench.php and XenForo’s own cmd.php commands (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.
  • A clean profile. The PGO rebuild reported 0 profile hash mismatches (the first run had 4).

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 wrk with 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 perf was 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.

Tierplain+ BOLT+ PGO+ PGO + BOLT
guest home327 [309-331]344 (+5.0 %) [334-350]355 (+8.4 %) [342-366]339 (+3.6 %) [335-349]
guest thread433 [402-440]451 (+4.3 %) [440-457]466 (+7.8 %) [442-479]451 (+4.2 %) [436-462]
member home305 [293-314]320 (+5.0 %) [317-320]326 (+7.1 %) [322-336]320 (+5.0 %) [316-321]
member thread346 [338-349]364 (+5.0 %) [361-366]367 (+6.1 %) [364-370]357 (+3.2 %) [354-358]

Median p99 latency fell for all three variants:

Tierplain+ BOLT+ PGO+ PGO + BOLT
guest home177 ms163 ms (-7.7 %)162 ms (-8.2 %)166 ms (-6.1 %)
guest thread130 ms123 ms (-5.6 %)123 ms (-5.8 %)122 ms (-6.0 %)
member home177 ms167 ms (-5.8 %)169 ms (-4.8 %)169 ms (-4.7 %)
member thread168 ms154 ms (-8.4 %)154 ms (-8.2 %)156 ms (-6.9 %)

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 perf2bolt couldn’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 rewrites php-fpm, so the CLI binaries of the BOLT arms are byte-identical to their bases and aren’t shown.

Scriptplain+ PGOChange (time)First run
bench.php, no JIT0.4390.460+4.8 % (slower)+10.3 %
micro_bench.php, no JIT2.2112.247+1.6 % (slower)+3.7 %
bench.php, JIT0.0910.093+2.2 %
micro_bench.php, JIT0.7810.777-0.5 %

With 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.php and micro_bench.php were 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#

  • One Zen 1 CPU, one application. No Zen 2 or Zen 3, no WordPress, no Chevereto.
  • The real CLI workload. bench.php stands in for cron jobs and imports. I didn’t time xf:run-jobs itself.
  • A CLI built without the profile. That’s the plan, not a measured arm. It should match plain, since it would be the plain build, but I haven’t run it.
  • No clock pinning, and SMT siblings. The pinned CPUs are the hyper-thread siblings of the ones the machine’s users run on, so the separation is by logical CPU, not by core. The neighbours were nearly idle throughout.
  • Round order. With five rounds over four arms, rounds 1 and 5 had the same order.

What it means for the script#

Across both machines, the picture is now consistent:

  • On CPUs without LBR (Zen 1 and 2), PGO alone. On Zen 1 it’s worth +6 to +8 % to XenForo, it won every comparison, and sample-based BOLT on top only costs speed. Zen 2 takes the same path in the script but hasn’t been measured. Sample-based BOLT alone is a weaker substitute for PGO, not a partner to it.
  • On CPUs with LBR (Intel, Zen 4 and newer), PGO followed by the LBR BOLT the script already runs. On the Xeon that combination was +7 to +10 % over plain but only -1.1 to +2.4 % over BOLT alone, so the Intel side still has to pass the 2 % rule in the release’s own A/B before it ships there.
  • php-fpm only. The CLI is built without the profile on every CPU, so cron jobs and imports should run as fast as today; that build hasn’t been benchmarked yet (see above).

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.md in ubuntu-setup-script.

Back to top ↑