Title: Tail calling interpreter for MSVC · Issue #139922 · python/cpython · GitHub
Open Graph Title: Tail calling interpreter for MSVC · Issue #139922 · python/cpython
X Title: Tail calling interpreter for MSVC · Issue #139922 · python/cpython
Description: Feature or enhancement Proposal: We should get tail calling interpreter support for MSVC. The latest up-to-date figures for the tail calling interpreter are: 1-3% pyperformance faster on Ubuntu x64 4-5% pyperformance faster on macOS AArc...
Open Graph Description: Feature or enhancement Proposal: We should get tail calling interpreter support for MSVC. The latest up-to-date figures for the tail calling interpreter are: 1-3% pyperformance faster on Ubuntu x64...
X Description: Feature or enhancement Proposal: We should get tail calling interpreter support for MSVC. The latest up-to-date figures for the tail calling interpreter are: 1-3% pyperformance faster on Ubuntu x64...
Opengraph URL: https://github.com/python/cpython/issues/139922
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Tail calling interpreter for MSVC","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nWe should get tail calling interpreter support for MSVC.\nThe latest up-to-date figures for the tail calling interpreter are:\n* 1-3% pyperformance faster on Ubuntu x64\n* 4-5% pyperformance faster on macOS AArch64\n* The last benchmarks for the tail calling interpreter on Windows MSVC reported a [17% speedup on pyperformance](https://github.com/mdboom/msvc-tailcall-analysis).\n\nOn Windows, the performance isn't easy to measure because `pyperf system tune` doesn't work on there. However, on a best-effort quiet system and some benchmarks from pyperformance on my system, these are my results:\n\n```\nMean +- std dev: [spectralnorm_tc_no] 146 ms +- 1 ms -\u003e [spectralnorm_tc] 98.3 ms +- 1.1 ms: 1.48x faster\nMean +- std dev: [nbody_tc_no] 145 ms +- 2 ms -\u003e [nbody_tc] 107 ms +- 2 ms: 1.35x faster\nMean +- std dev: [bm_django_template_tc_no] 26.9 ms +- 0.5 ms -\u003e [bm_django_template_tc] 22.8 ms +- 0.4 ms: 1.18x faster\nMean +- std dev: [xdsl_tc_no] 64.2 ms +- 1.6 ms -\u003e [xdsl_tc] 56.1 ms +- 1.5 ms: 1.14x faster\n```\nNote that I had to apply a 2-line patch to fix xDSL for Python 3.15.\n\nNbody and spectralnorm are toy shootout benchmarks. xDSL is a [new benchmark](https://github.com/python/pyperformance/blob/main/pyperformance/data-files/benchmarks/bm_xdsl/run_benchmark.py) added that is a MLIR DSL library with written almost entirely in pure Python. I consider it a pure-Python large library not too far off from mypy (though it's obviously smaller). 14% faster for xDSL is massive. It's roughly half of the [speedup we got in 3.11 with the specializing interpreter](https://github.com/EdmundGoodman/masters-project-report/tree/0f55308d74e9634de79ea32582bad0212693508d), and that was thousands of lines of code. This change in contrast will be just one PR. [Django templating](https://github.com/python/pyperformance/tree/main/pyperformance/data-files/benchmarks/bm_django_template) shows a big speedup too -- 18% faster.\n\nThis could not have been possible without help from the MSVC team. Specifically, I'd like to give a shoutout to Hulon Jenkins and the MSVC team in the patch notes when I land this.\n\nI've discussed this during the Wednesday CHIPS meetings, and there was no opposition to the new set of changes required to get this working. The changes are minimal and mostly just involve adding correct `restrict` and scoping to things to tell MSVC a local variable doesn't escape. This should also benefit GCC and Clang in some fashion.\n\nWe require working CI before this is merged, so I am now waiting on GitHub actions or some other CI to get this working.\n\nVery special shoutout as well to @chris-eibl who has been helping me with this on Windows.\n\nSome other benefits: the TC on MSVC actually correctly \"resets\" the inlining heuristic on MSVC. This means eventually we can get rid of all the macros and ugly hacks we have to make the current interpreter faster on MSVC once we distribute the builds with tail calling. Example of a hack where we use macros over static inlines on MSVC just because of the interpreter loop breaking the inliniing heuristics of MSVC https://github.com/python/cpython/issues/121263\n\n#### Possibility of a compiler bug this time\n\nI doubt it, as MSVC has no computed goto, so it can't have the same bug as Clang that we bumped into the previous time.\n\n#### Where are the perf gains coming from?\n\nIt's mainly the better inlining that we get from the tail calling interpreter, and elimination of double jumps vs the switch-case interpreter.\n\n### Has this already been discussed elsewhere?\n\nNo response given\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-139962\n* gh-143068\n* gh-143087\n* gh-143242\n* gh-146391\n* gh-146570\n* gh-148035\n* gh-148036\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/Fidget-Spinner","@type":"Person","name":"Fidget-Spinner"},"datePublished":"2025-10-10T19:36:02.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/139922/cpython/issues/139922"}
| 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:4d261ef6-8dec-cd17-b48f-0770eeb83763 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C77A:1E3EC6:669DB8:8C6128:6A514F96 |
| html-safe-nonce | 4ed1e2e1704a7ebe60f4d5249a6c2a5e6d0c99f07cfa5a1d17bbf3ce581e6394 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNzdBOjFFM0VDNjo2NjlEQjg6OEM2MTI4OjZBNTE0Rjk2IiwidmlzaXRvcl9pZCI6IjU4MjQzNDc5NTU4MDk4MzI4NTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 98b95906a47decacac0b75fdc463dbb68ce7c27c6cf0aa016372e5ae7fa36764 |
| hovercard-subject-tag | issue:3504282874 |
| 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/139922/issue_layout |
| twitter:image | https://opengraph.githubassets.com/16556345bb003c67cb78b84d3a0fcecaaa74a80139d4f8846633c2371130f7ce/python/cpython/issues/139922 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/16556345bb003c67cb78b84d3a0fcecaaa74a80139d4f8846633c2371130f7ce/python/cpython/issues/139922 |
| og:image:alt | Feature or enhancement Proposal: We should get tail calling interpreter support for MSVC. The latest up-to-date figures for the tail calling interpreter are: 1-3% pyperformance faster on Ubuntu x64... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Fidget-Spinner |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6f17634ed2af1d116850bcea6c63a70a4d72970f33ade1dd3eef3764b7e16994 |
| 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 | 511bff6ea06e144ed085ff736aea4c6404987b00 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width