Repository navigation
build: force ceval dispatch tail-duplication on affected Apple clangs (gh-158283) - #109
Merged
Merged
Conversation
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:17 — with
GitHub Actions
Inactive
ronaldtse
had a problem deploying
to
windows-signing
November 25, 2026 04:18 — with
GitHub Actions
Failure
ronaldtse
had a problem deploying
to
windows-signing
November 25, 2026 04:18 — with
GitHub Actions
Failure
ronaldtse
had a problem deploying
to
windows-signing
November 25, 2026 04:18 — with
GitHub Actions
Failure
ronaldtse
had a problem deploying
to
windows-signing
November 25, 2026 04:18 — with
GitHub Actions
Failure
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:18 — with
GitHub Actions
Inactive
ronaldtse
had a problem deploying
to
windows-signing
November 25, 2026 04:18 — with
GitHub Actions
Failure
ronaldtse
had a problem deploying
to
windows-signing
November 25, 2026 04:18 — with
GitHub Actions
Failure
ronaldtse
had a problem deploying
to
windows-signing
November 25, 2026 04:18 — with
GitHub Actions
Failure
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
had a problem deploying
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Error
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
temporarily deployed
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Inactive
ronaldtse
had a problem deploying
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Error
ronaldtse
had a problem deploying
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Error
ronaldtse
had a problem deploying
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Error
ronaldtse
had a problem deploying
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Error
ronaldtse
had a problem deploying
to
windows-signing
November 25, 2026 04:54 — with
GitHub Actions
Error
ronaldtse
force-pushed
the
fix/arm64-build-slowdown
branch
from
November 25, 2026 05:04
0bc70d8 to
19d79ea
Compare
… (gh-158283) Fresh macos-15 3.14.7 builds read fib-ratio 1.6-2.1 vs the same-leg on-system reference where the published v0.3.3 exe reads 1.0-1.33 on the same image (interleaved: fresh/v0.3.3 = 1.258 on one instance), with byte-identical recorded CONFIGURE_ARGS/OPT/CFLAGS, a byte-identical source tarball, and an unchanged dylib closure. The exe's _PyEval_EvalFrameDefault tells the story: v0.3.3 (Apple clang 15) carries 260 per-opcode indirect dispatch branches; the fresh build (Apple clang 17.0.0, Xcode 16.3 and 16.4 alike) carries ONE — every opcode handler direct-branches into a single shared dispatch site. gh-158283: LLVM 19 limited tail duplication of blocks ending in an indirect branch (llvm/llvm-project#78582), so clang lowers the computed-goto DISPATCH()es to one shared indirectbr that never gets copied back into the handlers — defeating the per-opcode branch prediction computed gotos exist for (upstream: ~9-13% pyperformance; our dispatch-dense fib sits at the hot end). Fixed in LLVM 20.1.1; Apple clang 1700.0.x carries the bug, 1700.3-1700.6 still merges most jumps. The x86_64 legs are hit too: the published v0.3.3 macos-x86_64 exes carry the same merged shape (1 indirect dispatch jump) — the Intel fleet has built with Xcode 16.3/16.4 all along. The remedy is CPython's own merged gh-158286, carried at the factory seam since the 3.14.7 configure predates it: the macOS legs compile the upstream identity-macro probe verbatim with the build's compiler, and an affected compiler arms -mllvm -tail-dup-pred-size=1000 for ceval.o ONLY — upstream measured regex_effbot 6-9% slower when the forced duplication reaches the regex engine's own computed goto, so a build-wide append would trade one regression for another. The channel is per-line: - 3.14+: CFLAGS_CEVAL, Makefile.pre's ceval-only knob, via the configure env (configure substitutes it and appends its own -finline-max-stacksize=512 probe result to the same variable). - pre-3.14: Makefile.pre carries no CFLAGS_CEVAL, so substitute_makefiles appends a GNU make target-specific binding (Python/ceval.o: CFLAGS_NODIST += ...) — ceval.o's recipe expands the target-local value through the recursive PY_CFLAGS_NODIST and every other TU (ceval_gil.o, _sre.o) expands the empty global. Marker-verified end to end against a configured 3.13.15 tree: the token lands on Python/ceval.o's compile line alone. Older clangs reject the option outright, so the gate is a compile probe, never a version sniff; the workaround self-retires when the fleet's toolchain leaves the affected window. ci/check_symbol_provenance.sh gains the artifact-level arm: the shipped exe's eval loop must carry >= 100 dispatch branches (a merged build carries 1). The count is arch-aware — arm64 `br <reg>`, x86_64 `jmpq *<operand>`; an arch-blind count reads 0 on Intel whatever the shape. Red/green-verified against the artifacts: v0.3.3 arm64 passes (260), the pre-fix CI build fails named (1), v0.3.3 x86_64 fails named (1 — the merged shape it shipped), the fixed x86_64 build passes (260). A probe miss on a future toolchain is now a named failure, never a green slow exe.
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The defect
Fresh macos-15 3.14.7/arm64 builds compute pure Python at ~1.6–2.1x the
same-leg on-system reference (the compute-floor ratio gate on
fix/compute-floor-ratio-gate), while the published v0.3.3 exe reads1.0–1.33 on the same image against the same reference (interleaved
three-arm probe, exp branch run 45377845849: fresh/v0.3.3 = 1.258 on
one instance). The recipe is comment-only-diff since v0.3.3, the
recorded
CONFIGURE_ARGS/OPT/CFLAGSin the two shipped env imagesare byte-identical, the source tarball is byte-identical
(sha256-verified), and
otool -Lshows the same five system dylibs —yet the fresh exe is a slower interpreter.
The mechanism — named
Apple clang 1700.x merges the ceval loop's per-opcode computed-goto
dispatch jumps into one shared indirect branch. This is
cpython#158283:
LLVM 19 limited tail duplication of blocks ending in an indirect branch
(llvm/llvm-project#78582).
Clang lowers each
DISPATCH()to one sharedindirectbrand relies onthe tail duplicator to copy it back into every opcode handler; the new
profitability limit stops that. Per-opcode branch prediction is the
entire point of computed gotos — a single shared dispatch site defeats
the BTB. Fully fixed in LLVM 20.1.1
(llvm/llvm-project#114990);
no 19.x release has the fix. Apple clang 1700.0.x (Xcode 16.3 and
16.4 — the macos-15 fleet's whole toolchain set) carries the same bug;
1700.3–1700.6 (Xcode 26.0–26.3) still merges most dispatch jumps.
Binary evidence (
_PyEval_EvalFrameDefaultdispatch-site counts, thisrepo's own artifacts unless noted):
ceval.c,-O3, localThe same shape flips with the compiler alone on one machine (pristine
3.14.7 source,
-O3): Apple clang 15 → 260 dispatch branches, upstreamLLVM 22 → 186, official LLVM 19.1.7 → 1, LLVM 19 + the flag → 284.
The speed tracks the shape: same-machine fib(35) fresh/v0.3.3 ≈ 1.26x
(matching the fleet's interleaved 1.258), while C-dominated workloads
(static openssl sha256, memcpy) are at parity — the tax is
dispatch-shaped, not allocator/interposition (corroborated by
tebako#1095's x86_64 closure: the preload shim never fires in the loop).
Upstream's own measurement on Xcode 16.4 (Apple clang 1700.0.13): one
dispatch jump left in the built exe; restoring duplication → 356–357
jumps and −11.4% pyperformance geomean. fib's call/dispatch density
sits at the hot end of that distribution, which is why our gate reads
1.6–2.1x.
Earlier false leads, closed by the exp branches: the tail-calling
interpreter (3.14.7's configure has no auto-probe; this recipe never
enabled it — both exes are the classic computed-goto ceval) and the
Xcode 16.3-vs-16.4 pin (same Apple clang 17 in both).
The fix
CPython's own merged remedy is gh-158286:
a compile probe on the compiler's identity macros arms
-mllvm -tail-dup-pred-size=1000forceval.conly — upstreammeasured regex_effbot 6–9% slower when the forced duplication reaches
the regex engine's own computed goto, so a build-wide flag would trade
one regression for another. The source configurations predate the
upstream patch, so this PR carries the same probe+flag at the factory
seam, per line:
PythonBuild#dispatch_tail_dup_env: the macOS legscompile upstream's identity-macro probe verbatim with the build's own
compiler; an affected compiler compiles it and
CFLAGS_CEVAL=-mllvm -tail-dup-pred-size=1000rides configure's env(Makefile.pre's ceval-only knob; configure substitutes it and appends
its own
-finline-max-stacksize=512probe result to the samevariable). Proven on the first push: the 3.14.7 legs restored 278
(arm64) / 260 (x86_64) dispatch sites and went green.
PythonBuild#dispatch_tail_dup_append: Makefile.precarries no
CFLAGS_CEVALbefore 3.14 (the first push's older legsfailed the new gate named at 1 dispatch site — the env channel never
reached their ceval.o, exactly the drift the arm exists to catch), so
substitute_makefilesappends a GNU make target-specific binding,Python/ceval.o: CFLAGS_NODIST += -mllvm -tail-dup-pred-size=1000.ceval.o's recipe expands the target-local value through the recursive
PY_CFLAGS_NODIST; every other TU (ceval_gil.o,_sre.o, thestdlib set) expands the empty global. Marker-verified end to end
against a configured 3.13.15 tree: the token lands on
Python/ceval.o's compile line alone.#error— older clangs reject the option outright, which is why thegate is a compile probe and never a version sniff; GCC legs never see
it; the workaround self-retires when the fleet leaves the affected
window.
ci/check_symbol_provenance.sh— a dispatch-shape arm (Mach-Olegs): the shipped exe's
_PyEval_EvalFrameDefaultmust carry ≥ 100indirect dispatch branches (a merged build carries 1; healthy shapes
185–360). The count is arch-aware — arm64
br <reg>, x86_64jmpq *<operand>(the first push's x86_64 legs "failed" at 0 countedbranches — an arch-blind
br-only count reads zero on Intel whateverthe shape; fixed and re-verified). Red/green-verified against the
artifacts: v0.3.3 arm64 passes (260), the pre-fix CI build fails
named (1), v0.3.3 x86_64 fails named (1 — the merged shape it
shipped), this PR's x86_64 build passes (260). A probe miss on a
future toolchain fails the leg by name, never ships a green slow exe.
spec/python_build_spec.rb: the probe's enablement semantics andthe per-line channel split (env on 3.14+, append pre-3.14, never
probed off-macOS), plus the probe text's verbatim mirror of
gh-158286's windows.
Deliberately NOT in this PR: PGO (a separate, larger recipe decision —
v0.3.3 had none either),
--with-tail-call-interp(3.14 marks itexperimental; the classic ceval is the shipped shape), a toolchain
switch (the fleet's clang is what it is; the flag makes it produce the
right bytes), and any re-baseline of the compute-floor gate (the gate
was right; the build was wrong).
What CI must prove
shows the probe firing (
gh-158283: the build compiler merges the computed-goto dispatch), the provenance gate counts ≥ 100 dispatchbranches, and the arm64 compute-floor fib(35) best-of-3 returns to
the healthy class (~1.3–2.0s on the current image, from the
defective 3.2–3.6s).
target-specific append lands — same ≥ 100 gate on the shipped exe.
no clang-only flag touches a GCC build; legs unchanged.
ruby -c, rspec.Side finding, out of scope here (owner attention): the v2.8.83 link-unit
exe fails to mount any env image on macOS 14.1.1 ("Failed to import
encodings module") where the v2.8.55 exe mounts both images fine and the
fresh exe boots with a PYTHONHOME override — a product-repo driver
question, not a factory one.