-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-114863: What's new in Python 3.13: JIT compiler #114862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-114863: What's new in Python 3.13: JIT compiler #114862
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi from a random stranger who knows very little about compilers 👋
I love the write up, it is very clear! Just some suggestions / questions.
Doc/whatsnew/3.13.rst
Outdated
and deduce information about types. This allows us to eliminate | ||
much of the overhead associated with dynamic typing in the future. | ||
|
||
* Constant propagation -- through forward data-flow analysis, we can reduce |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General comment: I wonder if for people who are compiler noobs but like to learn more it would be nice to link to wikipedia or other accessible sources? In this case, it is easy to google and find this: https://en.wikipedia.org/wiki/Constant_folding but in other cases it might not be?
(to be clear, I love the current text, it is very clearly written ❤️, so this does not seem as important)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the kind words! I think most of the terms are explained (I try to give a short summary of what they mean in each bullet point). Not all of this can be found in Wikipedia articles though, and some are found in particular programming language research papers.
Looks like the right level of detail, will review later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-Authored-By: Michael Droettboom <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I'm not convinced we should add this yet. In case we do decide to add it, here are some suggestions. But I'd like to focus the "What's new" document on useful information for Python users, plus the traditional credits ("contributed by XXX"). More details about how it works ought to go either in a .md document in the source code or maybe in the devguide (if it's valuable for maintainers) or in a personal or team blog (if it's more about academic results).
* Globals to constant promotion -- global value loads become constant | ||
loads, speeding them up and also allowing for more constant propagation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC this work is independent from the data-flow analysis part. It relies on dictionary watchers, which deserve a separate mention if they aren't already mentioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dictionary watchers were implemented in 3.12, not 3.13. So it's already mentioned there.
Doc/whatsnew/3.13.rst
Outdated
(Tier 2 optimizer contributed by Ken Jin, with implementation help | ||
by Guido van Rossum, Mark Shannon, and Jules Poon. Special thanks | ||
to Manuel Rigger and Martin Henz.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have to be a bit more careful here giving credit where due.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove Jules and Martin but I will insist on crediting Manuel, I've met with him consistently every 2 weeks to discuss this work (and adjacent experiments on optimizing CPython), and its technical details. This has been ongoing for over 5 months now. So I'm very thankful for his help.
Do you want to get this in before 3.13.0a4? (Scheduled for today, Tuesday, but delayed until tomorrow for the libexpat upgrade and some other fixes.) |
This shouldn't hold up the release. I'm okay with getting it in anytime before 3.13 beta. It might need major revision anyways to let the user know why they benefit. What do you think @gvanrossum ? |
Let’s hold off until we can agree on it. There’s a minimal thing in there already that’s not wrong. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As someone with modest familiarity with the topic I found it relatively straightforward to understand, and didn't find it that excessive purely as far as length-wise. On the other hand, I did find it read to me bit more to me like a (well-written) short blog post, or perhaps an Explanation in Diataxis terms, rather than a What's New.
IMO, this had less to do with the high-level content, and more in terms of structure, tone and how it presents information—it seemed to put more emphasis on discussing the hows and whys of the implementation and the optimization process as opposed to focusing on the main takeaways and user-facing impacts (optimizations, new CLI flags, future changes to expect, etc).
I think a comparison to the 3.11 What's New's Faster CPython section, which was referenced in this one and which this work is in part built upon, is instructive here. That was many times longer in total length, but is much more focused (in terms of the headings, text and structure) on the user-visible differences, performance impacts and high-level changes as opposed to an explaining of the non-user-facing low-level implementation details.
Some specific observations and suggestions:
-
Observation:The explanation of the Tier 2 IR seems to be rather long and prominent for something that's low-level internals, and focused on the implementation rather than on the main high-level changes.
Suggestion: Cut it down it down to just a sentence or two in the introduction, focusing on just the basic high-level changes the ultimately impacts users—there's a new tier 2 intermediate representation for hot code that allows more complex optimizations across function call boundaries.
-
Observation: I think it is valuable to point out the optimizations that this currently includes (like was done for 3.11), but with the focus on the impact of the optimization (i.e. how/why is this faster) rather than how it is currently written (focusing on the mechanics of how each code transformation is performed. For example, consider the very first bullet:
- Type propagation -- through forward data-flow analysis https://clang.llvm.org/docs/DataFlowAnalysisIntro.html_, we infer and deduce information about types.
This tells me what the mechanical transformation does internally, but skips over the much more important bit I care about as a user: How does this actually make my code faster (and what code does it affect)? Many of the others are similar in this regard.
Suggestion: Rewrite the bullets to focus on how each optimization actually makes mode faster (and when available, what code and by how much), and keep the explanations of the mechanics brief, high-level and frame in terms of "how does this make code faster" rather than being the main focus
-
Observation: Likewise, much of the information in the Execution Engine section is potentially useful, but the focus seems to be more on explaining the execution engines and copy and patch, with mentioning the user-impactful changes being secondary to that.
Suggestion: Consider reframing this section to enumerate the specific changes in 3.13. with brief explanations being secondary, in support of those rather than being the main focus.
-
Observation The results and future work reads, quite frankly, like what would find in a conference paper, and seems rather overblown for what it is.
Suggestion: It could be replaced with a brief note at the top of the overall section that performance improvement metrics will be added around the time of the first beta, and that the JIT is experimental and optimized and lays the ground work for the future.
I mainly kept most of Guido's original text, and split them into sections. I also added more exposition in certain parts (traces, optimization, execution engine). Let me know what y'all think.
PR as a follow up to #114826 for discussion.
📚 Documentation preview 📚: https://cpython-previews--114862.org.readthedocs.build/