Title: Switching between the JIT and interpreter is too slow. · Issue #136410 · python/cpython · GitHub
Open Graph Title: Switching between the JIT and interpreter is too slow. · Issue #136410 · python/cpython
X Title: Switching between the JIT and interpreter is too slow. · Issue #136410 · python/cpython
Description: A key part of the original design thesis for the JIT was that it was OK to jit small sections of code, provided that the cost of entering and exiting jjitted code was small enough. Ideally, entering (and exiting) jitted code should cost ...
Open Graph Description: A key part of the original design thesis for the JIT was that it was OK to jit small sections of code, provided that the cost of entering and exiting jjitted code was small enough. Ideally, enterin...
X Description: A key part of the original design thesis for the JIT was that it was OK to jit small sections of code, provided that the cost of entering and exiting jjitted code was small enough. Ideally, enterin...
Opengraph URL: https://github.com/python/cpython/issues/136410
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Switching between the JIT and interpreter is too slow.","articleBody":"A key part of the original design thesis for the JIT was that it was OK to jit small sections of code, provided that the cost of entering and exiting jjitted code was small enough.\nIdeally, entering (and exiting) jitted code should cost no more than 2 or 3 instruction dispatches in the interpreter.\n\nAt the moment, we are nowhere near that.\n\nTo achieve that low overhead, we need transfers to perform minimal memory accesses and use reasonably easily predictable branches.\n\n### What we have now \n#### ENTER_EXECUTOR\n\nThis is where code enters the jit. Currently this does an eval-breaker check (to avoid needing to perform an escaping call in the jit) then increfs the executor, to keep it alive, calls the shim frame, which then calls the actual jitted code.\n\n#### _EXIT_TRACE\n\nThis is where jitted code transfers control back to the interpreter or to other jitted code.\nThis uop contains complex logic to determine whether the exit is \"hot\", calls the jit compiler or jumps to other jitted code. Even in the case where jitted code already exists, it still needs to check for validity, before making a doubly dependent load to find the jitted code: `exit-\u003eexecutor-\u003ejitted_code`.\n\n### What we want:\n\nFirst of all, the interpreter and jit need to use the same calling convention. We can do this by using the tailcalling interpreter and TOS caching, such that the jitted code and interpreter functions take the same parameters.\n\nWe also want to refactor the executor or calling conventions, to save an indirection. ie. `exit-\u003ejit` rather than `exit-\u003eexecutor-\u003ejit`.\n\n#### ENTER_EXECUTOR\n\nWith the same calling convention, there should be no need for a shim frame. \nSo, apart from the eval-breaker check, `ENTER_EXECUTOR` only needs to find the executor and make the tailcall `executor-\u003ejit(...)`.\n\n#### _EXIT_TRACE\n\nBy handling cold exits and invalid executors in stubs, `_EXIT_TRACE` can avoid complex control flow and tailcall directly into the exit: `exit-\u003ejit(...)`.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-136411\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/markshannon","@type":"Person","name":"markshannon"},"datePublished":"2025-07-08T08:57:02.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/136410/cpython/issues/136410"}
| 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:22f0f7b3-32d3-f79f-c810-ffc1ae6ad013 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D30A:279D29:1D675D1:2905948:6A55F08F |
| html-safe-nonce | eac0a0e864c91d6119a0a98088a683e78a88c8f5b56cd8ed4936353757e0fe7c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzBBOjI3OUQyOToxRDY3NUQxOjI5MDU5NDg6NkE1NUYwOEYiLCJ2aXNpdG9yX2lkIjoiNTg0Mjk3MTY3MjczOTk2NzEyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 217738c51b20674f276591306257407fef77fab120d5ce9aa845a35b6282620e |
| hovercard-subject-tag | issue:3211654220 |
| 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/136410/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a3dd765a72dea45b92f8eb995e95d94ef0da627adfe3263b3a88479d1b97bfaf/python/cpython/issues/136410 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a3dd765a72dea45b92f8eb995e95d94ef0da627adfe3263b3a88479d1b97bfaf/python/cpython/issues/136410 |
| og:image:alt | A key part of the original design thesis for the JIT was that it was OK to jit small sections of code, provided that the cost of entering and exiting jjitted code was small enough. Ideally, enterin... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | markshannon |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e |
| 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 | 3725c7f9b2a6e3a27ef57c5aed13428c0f65e045 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width