Title: Computed-goto interpreter 9–13% slower when built with Clang 19 or Xcode 16.3–16.4: dispatch jumps are merged · Issue #158283 · python/cpython · GitHub
Open Graph Title: Computed-goto interpreter 9–13% slower when built with Clang 19 or Xcode 16.3–16.4: dispatch jumps are merged · Issue #158283 · python/cpython
X Title: Computed-goto interpreter 9–13% slower when built with Clang 19 or Xcode 16.3–16.4: dispatch jumps are merged · Issue #158283 · python/cpython
Description: When CPython is built with Clang 19, or with Apple clang from Xcode 16.3 or 16.4, the computed-goto interpreter ends up with a single shared indirect jump instead of one dispatch jump per opcode. Per-opcode branch prediction is the point...
Open Graph Description: When CPython is built with Clang 19, or with Apple clang from Xcode 16.3 or 16.4, the computed-goto interpreter ends up with a single shared indirect jump instead of one dispatch jump per opcode. P...
X Description: When CPython is built with Clang 19, or with Apple clang from Xcode 16.3 or 16.4, the computed-goto interpreter ends up with a single shared indirect jump instead of one dispatch jump per opcode. P...
Opengraph URL: https://github.com/python/cpython/issues/158283
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Computed-goto interpreter 9–13% slower when built with Clang 19 or Xcode 16.3–16.4: dispatch jumps are merged","articleBody":"When CPython is built with Clang 19, or with Apple clang from Xcode 16.3 or 16.4, the computed-goto interpreter ends up with a single shared indirect jump instead of one dispatch jump per opcode. Per-opcode branch prediction is the point of computed gotos; restoring it makes pyperformance 8–9% faster on Linux and 11% faster on macOS arm64 with Xcode 16.4. Put the other way round, current builds with these compilers are 9–13% slower.\n\nLLVM 19 limited tail duplication of blocks that end in an indirect branch (llvm/llvm-project#78582). Clang lowers all computed gotos to one shared `indirectbr` block and relies on tail duplication to copy it back into each predecessor; the new limit stops that. LLVM 20.1.0 fixed this partially (llvm/llvm-project#116072) and 20.1.1 fully (llvm/llvm-project#114990). No 19.x release has the fix. Xcode 26.0–26.3 has the partial fix; it still merges most dispatch jumps, but the cost is only 1.4%.\n\nGCC builds and the tail-calling interpreter (`--with-tail-call-interp`) are not affected.\n\nNelson Elhage [found in March 2025](https://blog.nelhage.com/post/cpython-tail-call/) that this LLVM 19 regression accounted for most of the originally reported speedup of the 3.14 tail-calling interpreter. His issue about merged dispatch jumps, gh-129987, was closed after gh-132295 and gh-132530, which changed GCC's SLP vectorization; Clang 19 builds still have one dispatch jump.\n\n### Measurements\n\nIndirect jumps in `_PyEval_EvalFrameDefault`, in `Python/ceval.o` built at `-O3` (x86-64) and in the final PGO+LTO binary. PGO builds are not deterministic, so the PGO+LTO counts are ranges over the independent builds:\n\n| compiler | `-O3` object | PGO+LTO binary |\n|---|---|---|\n| GCC 12 / 13 / 14 | 257 | 234 |\n| Clang 18 | 269 | not measured |\n| Clang 19.1.7 | 1 | 1–9 |\n| Clang 19.1.7 + `-mllvm -tail-dup-pred-size=1000` | 269 | 356–360 |\n| Clang 21 | 268 | 354–362 |\n\npyperformance on x86-64 Linux GitHub runners, main at 6af40a6. Each experiment used a randomized block design with the builds interleaved per benchmark and a same-binary control; the 95% confidence interval is a bootstrap over independent builds. Negative is faster.\n\n| comparison | build | builds | geomean | 95% CI |\n|---|---|---|---|---|\n| Clang 19 + `-mllvm -tail-dup-pred-size=1000` vs Clang 19 | PGO+LTO | 6 | −8.6% | [−9.6, −7.4] |\n| Clang 19 vs GCC 13 | PGO+LTO | 6 | +7.7% | [+6.4, +8.7] |\n| Clang 19 + flag vs GCC 13 | PGO+LTO | 6 | −1.6% | [−1.8, −1.3] |\n| gh-158286 vs main, Clang 19 | PGO+LTO | 6 | −8.4% | [−9.5, −6.9] |\n| gh-158286 vs main, Clang 19 | thin LTO, no PGO (FreeBSD's configuration) | 8 | −8.7% | [−9.2, −8.3] |\n\nThe same-binary controls were within ±0.2%. The biggest single-benchmark gains are 18–24% (unpack_sequence, deepcopy_memo, nbody, scimark_sor); regex_effbot gets 6–9% slower. Under LTO the option also un-merges the regex engine's own computed-goto dispatch, and the regex_effbot slowdown depends strongly on code layout: with three randomised layouts per build it is 1–9% on the EPYC 7763 runners, and the three regex benchmarks together show no significant change ([data](https://github.com/matthiasgoergens/cpython/tree/clang19-dispatch-data/experiments/exp13-sre-layout); details in gh-158286).\n\nmacOS 15 arm64 GitHub runners, PGO+LTO, gh-158286 vs main:\n\n| compiler | dispatch jumps before → after | builds | geomean | 95% CI |\n|---|---|---|---|---|\n| Xcode 16.4 (Apple clang 1700.0.13) | 1 → 356–357 | 5 | −11.4% | [−13.2, −9.8] |\n| Xcode 26.3 (Apple clang 1700.6) | 110–121 → 356–358 | 5 | −1.4% | [−2.2, −0.7] |\n\nThese runners are noisier; the same-binary control there was −0.4% [−1.8, +0.9].\n\nRaw data, configurations and scripts: https://github.com/matthiasgoergens/cpython/tree/clang19-dispatch-data\n\n### Affected builds\n\nChecked against the compiler string in shipped binaries where possible:\n\n- FreeBSD 14 and 15 packages, python311 to python314 (base clang 19.1.7, thin LTO)\n- OpenBSD 7.8 and 7.9, python 3.12 and 3.13 (base clang 19.1.7)\n- OpenMandriva Lx 6.0, python 3.11 (clang 19.1.7)\n- macOS builds made with Xcode 16.3 or 16.4, for example MacPorts python313 and python314 on macOS 15: one dispatch jump left\n- macOS builds made with Xcode 26.0–26.3, for example Homebrew's macOS 15 bottles: 94 of ~300 (arm64) or 62 of ~276 (x86-64) dispatch jumps left in a `--with-lto` build\n\npython-build-standalone/uv (January–February 2025) and conda-forge's macOS builds also used Clang 19 for a while, but have since moved on. Xcode 26.4 and later still merge some dispatch jumps (200 in `ceval.o`, 328 with the option added by hand); gh-158286 leaves them alone.\n\n### Proposed fix\n\ngh-158286 passes `-mllvm -tail-dup-pred-size=1000` when compiling `ceval.c` with Clang 19 or Apple clang 1700.x (Xcode 16.3–26.3), and to the linker with LTO.\n\n### CPython versions tested on:\nCPython main branch\n\n### Operating systems tested on:\nLinux, macOS\n\n\n","author":{"url":"https://github.com/matthiasgoergens","@type":"Person","name":"matthiasgoergens"},"datePublished":"2026-09-27T14:23:01Z","url":"https://github.com/python/cpython/issues/158283"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c5325ed7-8955-7852-55aa-2c46dea95d49 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AA48:2A98A:C0BD0F:F26B5A:6B023A97 |
| html-safe-nonce | d8ea7614ab8c5368f416d7cfabd4d25a782d8882189754547dd5738da63635fb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQTQ4OjJBOThBOkMwQkQwRjpGMjZCNUE6NkIwMjNBOTciLCJ2aXNpdG9yX2lkIjoiMjc5NDkwMjYxMzM1NzkwMjQ4NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 84e0442ae4420ea2cee36dc11cf5c4d9eb8920dc6126486aac868f3d21e1dab4 |
| hovercard-subject-tag | issue:5603403176 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/158283/issue_layout |
| twitter:image | https://opengraph.githubassets.com/aa3165f457f7971cac54aff3e2c85fc5d94760708ef1c493796687fa09dbfc42/python/cpython/issues/158283 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/aa3165f457f7971cac54aff3e2c85fc5d94760708ef1c493796687fa09dbfc42/python/cpython/issues/158283 |
| og:image:alt | When CPython is built with Clang 19, or with Apple clang from Xcode 16.3 or 16.4, the computed-goto interpreter ends up with a single shared indirect jump instead of one dispatch jump per opcode. P... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | matthiasgoergens |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width