GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-113464: A copy-and-patch JIT compiler by brandtbucher · Pull Request #113465 · python/cpython

Conversation

@brandtbucher

@brandtbucher brandtbucher commented Dec 25, 2023 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

'Twas the night before Christmas, when all through the code
Not a core dev was merging, not even Guido;
The CI was spun on the PRs with care
In hopes that green check-markings soon would be there;
The buildbots were nestled all snug under desks,
Even PPC64 AIX;
Doc-writers, triage team, the Council of Steering,
Had just stashed every change and stopped engineering,

When in the "PRs" tab arose such a clatter,
They opened GitHub to see what was the matter.
Away to CPython they flew like a flash,
Towards sounds of PROT_EXEC and __builtin___clear_cache.
First LLVM was downloaded, unzipped
Then the Actions were running a strange new build script,
When something appeared, they were stopped in their tracks,
jit_stencils.h, generated from hacks,
With their spines all a-shiver, they muttered "Oh, shit...",
They knew in a moment it must be a JIT.

More rapid than interpretation it came
And it copied-and-patched every stencil by name:
"Now, _LOAD_FAST! Now, _STORE_FAST! _BINARY_OP_ADD_INT!
On, _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT!
To the top of the loop! And down into the call!
Now cache away! Cache away! Cache away all!"
But why now? And how so? They needed a hint,
Thankfully, Brandt gave a great talk at the sprint;
So over to YouTube the reviewers flew,
They read the white paper, and the blog post too.

And then, after watching, they saw its appeal
Not writing the code themselves seemed so unreal.
And the platform support was almost too easy,
ARM64 Macs to 32-bit PCs.
There was some runtime C, not too much, just enough,
Basically a loader, relocating stuff;
It ran every test, one by one passed them all,
With not one runtime dependency to install.
Mostly build-time Python! With strict static typing!
For maintenance ease, and also nerd-sniping!

Though dispatch was faster, the JIT wasn't wise,
And the traces it used still should be optimized;
The code it was JIT'ing still needed some thinning,
With code models small, and some register pinning;
Or new calling conventions, shared stubs for paths slow,
Since this JIT was brand new, there was fruit hanging low.
It was awkwardly large, parsed straight out of the ELFs,
And they laughed when they saw it, in spite of themselves;

A configure flag, and no merging this year,
Soon gave them to know they had nothing to fear;
It wasn't much faster, at least it could work,
They knew that'd come later; no one was a jerk,
But they were still smart, and determined, and skilled,
They opened a shell, and configured the build;
--enable-experimental-jit, then made it,
And away the JIT flew as their "+1"s okay'ed it.
But they heard it exclaim, as it traced out of sight,
"Happy JIT-mas to all, and to all a good night!"

  • Issue: JIT Compilation #113464

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hmenke, shner-elmo, tusharsadhwani, pablogsal, Titaniumtown, DanielNoord, KrunoSaho, emmatyping, rafo, tshirtman, and 321 more reacted with thumbs up emoji Explosion-Scratch reacted with thumbs down emoji hugovk, ilya-nikolaev, hroncok, blink1073, benjaoming, john-hen, wookie184, shner-elmo, vasily-v-ryabov, itamaro, and 356 more reacted with laugh emoji davidbrochart, erlend-aasland, tusharsadhwani, tekknolagi, carljm, kalvdans, viraptor, danielloader, emmatyping, nmstoker, and 144 more reacted with hooray emoji Eclips4, hugovk, adamchainz, leouieda, PaarthShah, marksweb, CharlieZhao95, TheArcherST, vadim-su, ssweber, and 305 more reacted with heart emoji AlexWaygood, hugovk, Eclips4, n05tr0m0, shner-elmo, erlend-aasland, tusharsadhwani, tekknolagi, pablogsal, corona10, and 91 more reacted with rocket emoji ducdetronquito, wilsonjholmes, Codwizer, nbyidiandian, z11h, ycd, wcrum, birdcar, gabrielfalcao, roma-glushko, and 9 more reacted with eyes emoji
All reactions
  • 👍 331 reactions
  • 👎 1 reaction
  • 😄 366 reactions
  • 🎉 154 reactions
  • ❤️ 315 reactions
  • 🚀 101 reactions
  • 👀 19 reactions
brandtbucher and others added 30 commits September 1, 2023 11:19
@brandtbucher
Remove the ip_offset hack and executor local
8f6c5fe
@brandtbucher
Merge branch 'main' into justin
e0888de
@brandtbucher
Get rid of ip_offset
365f7a2
@brandtbucher
Catch up with main
7fb79b8
@brandtbucher
fixup
66a5659
@brandtbucher
Catch up with main
f90bd1e
@brandtbucher
Crank up the trace length for nbody
a98d4fe
@brandtbucher
Catch up with main
dc308ba
@brandtbucher
Add rough assembly dumps to jit_stencils.h
f2b18d7
@brandtbucher
Make machine code disassemblies more robust
e2ae7bc
@brandtbucher
Go back to llvm-objdump like the good 'ol days
be88965
@brandtbucher
Remove old debugging struct
56976b3
@brandtbucher
-fno-pic
e33b4ab
@brandtbucher
Take a triple (and debug flag) instead of guessing
3ac1946
@brandtbucher
Use more regular configs and fix debug builds
50731b5
@brandtbucher
Try using cross-compiles for aarch64
e559898
@brandtbucher
Fix quotes
317ba79
@brandtbucher
apt update
07e03a1
@brandtbucher
No pkg-config
e649059
@brandtbucher
Fix PGO and disable multiprocessing
11c7f44
@brandtbucher
Add missing excludes
4981573
@brandtbucher
Switch to enums
1688830
@brandtbucher
Catch up with main
29936e6
@brandtbucher
More cleanup
ed75bd6
@brandtbucher
Rename some things, and don't constantly regen
8488def
@brandtbucher
Clean up a bunch of stuff
28351a0
@brandtbucher
Patch opargs and operands in the continuation
cc5db79
@brandtbucher
Fix GHCCC hack
f2817bb
@brandtbucher
Blacken
fb96638
@brandtbucher
Fix incorrect signature
77e1487
markshannon
markshannon reviewed Jan 22, 2024
View reviewed changes
Comment thread Tools/jit/_writer.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

JeffersGlass
JeffersGlass reviewed Jan 24, 2024
View reviewed changes
Comment thread Tools/jit/build.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread configure Resolved

Uh oh!

There was an error while loading. Please reload this page.

brandtbucher added 9 commits January 25, 2024 11:15
@brandtbucher
Don't include Python/, add a --force option, and unify section/symbol…
81d0fb6
… lookup
@brandtbucher
Make _PyJIT_Compile take a trace and length
437bc53
@brandtbucher
Move header comment to build.py
26e248a
@brandtbucher
Clean up the schema
f3984e6
@brandtbucher
Reorder some keys
113a1f1
@brandtbucher
Rearrange (and add) comments for patch function
6648d84
@brandtbucher
Use generated pyconfig.h directory
46bee49
@brandtbucher
Catch up with main
c33c78f
@brandtbucher
Add back Python/ include
4d3e207
@brandtbucher

brandtbucher commented Jan 26, 2024

Copy link
Copy Markdown
Member Author

Alright, I think I've addressed everyone's comments. Thanks for the reviews... this PR is looking better than ever!

If anyone is planning on reviewing this, please do so now. Otherwise, my plan is to merge this first thing on Monday.

(I've confirmed that the two CI failures are failing on main too, and aren't JIT-related).

JeffersGlass, hidaris, ericsnowcurrently, JixS4v, hugovk, rafalp, JesseChin, penguin-wwy, ipfans, rdenadai, and 9 more reacted with hooray emoji stonebig, JixS4v, rafalp, JesseChin, scastlara, erlend-aasland, 0xsirsaif, rafaeljcd, cemrehancavdar, PierrickV, and 4 more reacted with heart emoji davidbrochart, rafalp, JesseChin, Eclips4, cryptic-quasar, rdenadai, erlend-aasland, 0xsirsaif, rafaeljcd, PierrickV, and 3 more reacted with rocket emoji
All reactions
  • 🎉 19 reactions
  • ❤️ 14 reactions
  • 🚀 13 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher
Catch up with main
581036e
z764969689 pushed a commit to z764969689/cpython that referenced this pull request Jan 29, 2024
@brandtbucher
pythonGH-113464: Add a JIT backend for tier 2 (pythonGH-113465)
f6d9e59
Add an option (--enable-experimental-jit for configure-based builds
or --experimental-jit for PCbuild-based ones) to build an
*experimental* just-in-time compiler, based on copy-and-patch (https://fredrikbk.com/publications/copy-and-patch.pdf).

See Tools/jit/README.md for more information on how to install the required build-time tooling.
@brandtbucher
Merge branch 'main' into justin
b00e021
@brandtbucher

brandtbucher commented Jan 29, 2024

Copy link
Copy Markdown
Member Author

Well, due to a GitHub UI glitch, the merge button errored out when I pushed it, leaving the PR open. But never fear... it was indeed merged (twice)!

Thanks again, everybody. :)

stonebig, PierrickV, Zheaoli, Slach, rnetonet, felipek, caio-truewind, nkhitrov, leycec, Mskxn, and iluvvatar reacted with thumbs up emoji hugovk, Eclips4, hidaris, j178, NeilBotelho, ermakov-oleg, spiqueras, erlend-aasland, olivierphi, rdenadai, and 25 more reacted with hooray emoji davidbrochart, erlend-aasland, MarshalX, rdenadai, chrisknight32, ambv, 0xsirsaif, aeby, ericpalakovichcarr, noamelf, and 13 more reacted with heart emoji hugovk, Eclips4, gglin001, hidaris, AlexWaygood, danielhollas, alexprengere, erlend-aasland, itamaro, rdenadai, and 22 more reacted with rocket emoji
All reactions
  • 👍 11 reactions
  • 🎉 35 reactions
  • ❤️ 23 reactions
  • 🚀 32 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher brandtbucher closed this Jan 29, 2024
@gvanrossum

gvanrossum commented Jan 29, 2024

Copy link
Copy Markdown
Member

Congrats! Well done.

brandtbucher, rdenadai, arusahni, patrick91, 0xsirsaif, centaurialpha, tab1tha, psobot, dolfinus, GalaxySnail, and 50 more reacted with heart emoji
All reactions
  • ❤️ 60 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Yhg1s

Yhg1s commented Jan 31, 2024

Copy link
Copy Markdown
Member

As Release Manager, and after talking this through with the Steering Council, I'm going to have to ask: where is the PEP for this, or some other kind of document explaining the design decisions and the discussions around it? Why was it merged now, without a PEP or wide discussion among Core Developers, especially since the immediate performance benefit is pretty much non-existent?

We have the PEP process for a reason. For longevity of CPython, it's important to not just add new features, but also bring along other Core Developers in their design -- especially since we all implicitly adopt the maintenance of it. Even optional bits, because they are all part of the support surface (especially when they're desirable features). We also have a standing policy not to experiment in main, and while I understand the upside of merging this early and then iterating on it, especially given how it meshes with other improvements to uops and what not, this feels like it's close to doing just that: experimenting in main. Merging it and iterating makes it much harder to revert it later, should that turn out to be necessary. That's not to say that it mustn't be merged, but it should be considered an exception and done with some deliberation with the RM or the SC.

How much follow-up work relies on this being merged, now? How difficult would it be to revert now and merge again later?

erlend-aasland, warsaw, gpshead, j178, scastlara, eendebakpt, SigureMo, lockie, agriyakhetarpal, and phase reacted with thumbs up emoji brandtbucher, caio-truewind, jm-nab, theLastOfCats, and baggiponte reacted with confused emoji ornew, mi-skam, rainzee, jm-nab, and daler-sz reacted with eyes emoji
All reactions
  • 👍 10 reactions
  • 😕 5 reactions
  • 👀 5 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher

brandtbucher commented Feb 1, 2024

Copy link
Copy Markdown
Member Author

Thanks for voicing your concerns.

As Release Manager, and after talking this through with the Steering Council, I'm going to have to ask: where is the PEP for this, or some other kind of document explaining the design decisions and the discussions around it? Why was it merged now, without a PEP or wide discussion among Core Developers, especially since the immediate performance benefit is pretty much non-existent?

There isn't a PEP for this. If I were to write one today, it would basically cover all of the same points as the talk I gave at the October sprint (slides, paper, blog post).

Despite the absence of a PEP, I feel that this was widely-discussed with core devs. Just to recap the timeline...

I first introduced this patch at the core dev sprint last year, on October 10th, in a 48-minute talk and Q&A. During the Q&A, I said:

If this is something people would like to see in main, off by default, we can get it in main very easily. I know we aren't crazy about experiments in main, which is kind of why I'm floating the idea now.

The video was shared with all core devs that same day. In both the in-person and follow-up Discourse discussion, I personally perceived the feedback to be very positive (much more positive than I anticipated). Maybe I misread the room, but the response convinced me that this wasn't very hard-to-understand or controversial (except for parts of the build process, in particular the LLVM requirement).

Twenty days later, on October 30th, I made the following comment on Discourse, visible to all committers:

An update: my current goal is to merge this initial implementation (behind a build flag, off by default) before the American Thanksgiving holiday. That’s on Thursday, November 23rd… which means I’ll probably be opening the PR around Friday the 17th. Active development can then continue on main (which seemed okay with people at the sprint).

Nobody objected. That deadline came and went, and a month later the PR itself was published as a draft for 24 days, then open for an additional 11 days before merging (which I announced 3 days in advance).

Merging it and iterating makes it much harder to revert it later, should that turn out to be necessary. That's not to say that it mustn't be merged, but it should be considered an exception and done with some deliberation with the RM or the SC.

How much follow-up work relies on this being merged, now? How difficult would it be to revert now and merge again later?

Part of the reason why there's a negligible performance impact right now is because it purposefully omits lots of "obvious" performance improvements in order to keep the initial JIT implementation as small and easy-to-review as possible. I'd rather have each one of them be reviewed on their own merits than develop a more-and-more sophisticated JIT that we all feel pressure to merge before the beta freeze.

I don't believe these changes would make reverting any more difficult, since they'll probably be isolated to new files (git revert f6d9e59 works fine right now on main).

Should one of us open an issue on the SC tracker?

JelleZijlstra, flofriday, scastlara, Eclips4, AlexWaygood, uhbif19, cosmtrek, caio-truewind, mnrozhkov, geiccobs, and 6 more reacted with thumbs up emoji
All reactions
  • 👍 16 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xorrvin xorrvin mentioned this pull request Feb 10, 2024
JIT extension erlang/otp#8110
Closed
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
@brandtbucher @aisk
pythonGH-113464: Add a JIT backend for tier 2 (pythonGH-113465)
a4c3b8f
Add an option (--enable-experimental-jit for configure-based builds
or --experimental-jit for PCbuild-based ones) to build an
*experimental* just-in-time compiler, based on copy-and-patch (https://fredrikbk.com/publications/copy-and-patch.pdf).

See Tools/jit/README.md for more information on how to install the required build-time tooling.
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
@brandtbucher @aisk
pythonGH-113464: A JIT backend for tier 2 (pythonGH-113465)
534119a
Add an option (--enable-experimental-jit for configure-based builds
or --experimental-jit for PCbuild-based ones) to build an
*experimental* just-in-time compiler, based on copy-and-patch
(https://fredrikbk.com/publications/copy-and-patch.pdf).

See Tools/jit/README.md for more information, including how to install the required build-time tooling. Merry JIT-mas! ;)
@jakirkham jakirkham mentioned this pull request Feb 18, 2024
Building Python 3.13 dev releases + no GIL conda-forge/python-feedstock#658
Closed
@Yhg1s

Yhg1s commented Feb 28, 2024

Copy link
Copy Markdown
Member

I'm glad to hear you think the discussion was wide-spread enough. I'm not really concerned that the JIT wasn't researched or reviewed enough, although I will say that I tuned out the discussion about your presentation on discuss.python.org because I was expecting a PEP once it was fleshed out (and I don't believe I was the only one).

I do believe a PEP is warranted, even at this stage. A PEP isn't just for making decisions, it's also for recording the history of the decisions (and the process around it), and to set boundaries and limitations to a particular feature. It's where people (core developers and others) will look for answers to questions they have about this feature. A PEP that summarises (or links to) arguments previously made is fine. I (and the SC) would like it to address questions like:

  • What's the story for inspecting the runtime with the JIT enabled, like with perf or C debuggers (not PEP 669 debuggers, which I assume are unaffected)?
  • What are the effects on and limitations of the JIT in terms of code size, binary size, memory use, etc? I remember in October we talked about 32-bit offsets which I know is going to be problematic in certain situations.
  • What other downsides, negative effects and subtle semantic differences can people expect when they enable this in their builds?
  • How are we going to determine whether this should be promoted from an experimental feature to one we recommend, or even one we make the default?
GalaxySnail, erlend-aasland, rdenadai, viliamjr, xncbf, agriyakhetarpal, phase, eirannejad, davidlatwe, Mark90, and efimov-mikhail reacted with thumbs up emoji
All reactions
  • 👍 11 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher

brandtbucher commented Feb 28, 2024

Copy link
Copy Markdown
Member Author

Okay, makes sense. I'll start on a PEP.

erlend-aasland, aguiddir, soltanoff, rdenadai, BorodaOmsk, viliamjr, cbueth, xncbf, and agriyakhetarpal reacted with hooray emoji
All reactions
  • 🎉 9 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

WillChilds-Klein pushed a commit to WillChilds-Klein/cpython that referenced this pull request Mar 4, 2024
@brandtbucher @WillChilds-Klein
pythonGH-113464: A JIT backend for tier 2 (pythonGH-113465)
d6f355e
Add an option (--enable-experimental-jit for configure-based builds
or --experimental-jit for PCbuild-based ones) to build an
*experimental* just-in-time compiler, based on copy-and-patch
(https://fredrikbk.com/publications/copy-and-patch.pdf).

See Tools/jit/README.md for more information, including how to install the required build-time tooling. Merry JIT-mas! ;)
@brandtbucher

brandtbucher commented Apr 12, 2024

Copy link
Copy Markdown
Member Author

At long last, the PEP is up: https://discuss.python.org/t/pep-744-jit-compilation

viliamjr, hugovk, erlend-aasland, itamaro, Eclips4, ifduyue, dolfinus, tusharsadhwani, vitaldmit, howard36, and 8 more reacted with hooray emoji stonebig, eirannejad, oleksandr-kuzmenko, leycec, agriyakhetarpal, flofriday, AgarwalPragy, and maverick0025 reacted with heart emoji
All reactions
  • 🎉 18 reactions
  • ❤️ 8 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher brandtbucher added the topic-JIT label May 31, 2024
brandtbucher added a commit to brandtbucher/cpython that referenced this pull request Aug 20, 2025
@brandtbucher
Revert "pythonGH-113464: Add a JIT backend for tier 2 (pythonGH-113465)"
f7e2616
This reverts commit f6d9e59.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@corona10 corona10 corona10 left review comments
@Eclips4 Eclips4 Eclips4 left review comments
@markshannon markshannon markshannon left review comments
@mdboom mdboom mdboom left review comments
@sobolevn sobolevn sobolevn left review comments
@gvanrossum gvanrossum gvanrossum left review comments
@zooba zooba zooba left review comments
@hugovk hugovk hugovk left review comments
@ericsnowcurrently ericsnowcurrently ericsnowcurrently left review comments
@ronaldoussoren ronaldoussoren ronaldoussoren left review comments
@erlend-aasland erlend-aasland erlend-aasland approved these changes
@ezio-melotti ezio-melotti Awaiting requested review from ezio-melotti
+9 more reviewers
@PaarthShah PaarthShah PaarthShah left review comments
@penguin-wwy penguin-wwy penguin-wwy left review comments
@thesamesam thesamesam thesamesam left review comments
@pinskia pinskia pinskia left review comments
@HacKanCuBa HacKanCuBa HacKanCuBa left review comments
@eli-schwartz eli-schwartz eli-schwartz left review comments
@davidbrochart davidbrochart davidbrochart left review comments
@JeffersGlass JeffersGlass JeffersGlass left review comments
@tonybaloney tonybaloney tonybaloney left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@brandtbucher brandtbucher

Labels

awaiting merge interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage topic-JIT

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

20 participants

@brandtbucher @adrian17 @jessekrubin @Zheaoli @alphavector @Eclips4 @penguin-wwy @tekknolagi @ericsnowcurrently @bedevere-bot @gvanrossum @Yhg1s @mdboom @ronaldoussoren @hugovk @tonybaloney @zooba @JeffersGlass @sobolevn @davidbrochart
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.