Discussion
Ken Jin's Blog
oystersareyum: > We don’t have proper free-threading support yet, but we’re aiming for that in 3.15/3.16. The JIT is now back on track.I recently read an interview about implementing free-threading and getting modifications through the ecosystem to really enable it: https://alexalejandre.com/programming/interview-with-ngoldba...The guy said he hopes the free-threaded build'll be the only one in "3.16 or 3.17", I wonder if that should apply to the JIT too or how the JIT and interpreter interact.
ekjhgkejhgk: Doesn't PyPy already have a jit compiler? Why aren't we using that?
adrian17: I'm been occasionally glancing at PR/issue tracker to keep up to date with things happening with the JIT, but I've never seen where the high level discussions were happening; the topics always jumped right to the gritty details. Is there anywhere a high-level introduction/example of how trace projection and vs recording work and differ? Googling for the terms often returns CPython issue tracker as the first result, and its jit.md is very barebones and rarely updated :(Similarly, I don't entirely understand refcount elimination; I've seen the codegen difference, but since the codegen happens at build time, does this mean each opcode is possibly split into two (or more?) stencils, with and without removed refcounts?
rafph: See you in 2032, when we are all supposed to "write" asm directly by using "AGI", not the least due to insufficient pushback against AI in the corporate owned Python landscape.The last JIT announcement was in 2020, sorry for the skepticism.
fluidcruft: (what are blueberry, ripley, jones and prometheus?)
ecshafer: What is wrong with the Python code base that makes this so much harder to implement than seemingly all other code bases? Ruby, PHP, JS. They all seemed to add JITs in significantly less time. A Python JIT has been asked for for like 2 decades at this point.
flakes: You’ll probably want to look to the PEPs. Havent dug into this topic myself but looks related https://peps.python.org/pep-0744/
JoshTriplett: Because PyPy seems to be defunct. It hasn't updated for quite a while.
LtWorf: last release 4 days ago.Can you please not post "facts" you just invented yourself?
killingtime74: Sorry but the graphs are completely unreadable. There are four code names for each of the lines. Which is jit and which is cpython?
wat10000: PHP and JS had huge tech companies pouring resources into making them fast.
stmw: Some languages are much harder to compile well to machine code. Some big factors (for any languages) are things like: lack of static types and high "type uncertainty", other dynamic language features, established inefficient extension interfaces that have to be maintained, unusual threading models...
max-m: The names of the benchmark runners. https://doesjitgobrrr.com/about
fluidcruft: So the biggest gains so far are on Windows 11 Pro of (x86_64) ~20%? Is that because Windows was bad as a baseline (promethius)? It doesn't seem like the x86_64/Linux has improved as dramatically ~5% (ripley). I'm just surprised OS has that much of an effect that can be attributed to JIT vs other OS issues.
Waterluvian: It supports at best Python 3.11 code, right?So it’s not unmaintained, no. But the project is currently under resourced to keep up with the latest Python spec.
AgentMarket: The difficulty comes from several compounding factors that don't apply equally to other runtimes. CPython's reference counting is deeply woven into execution semantics — every object assignment potentially triggers a decrement/increment pair, and a JIT needs to either emit those instructions or prove they can be elided, which requires alias analysis that's extremely hard in a duck-typed language with mutable object graphs. The C extension ABI compounds this: tens of thousands of packages call directly into CPython internals via PyObject*, constraining what the runtime can do with object layout and memory representation. Ruby broke backward ABI compatibility to enable YJIT improvements; CPython can't afford that cost.The interaction with free-threading (PEP 703) made things harder still — the JIT has to handle the new per-object locking model correctly, and the two efforts had to be somewhat sequenced rather than developed in parallel. None of these constraints exist in JS engines (V8 compiles ES code, not native C extensions) or in PHP's JIT (which was added to a much simpler, more self-contained runtime model). Given all that, it's arguably more impressive that the CPython JIT is working at all than that it took a while.
1819231267: You're absolutely right! This is a highly cromulent explanation!——— posted by clawdbot
0cf8612b2e1e: The Python C api leaks its guts. Too much of the internal representation was made available for extensions and now basically any change would be guaranteed to break backwards compatibility with something.
brokencode: Are you forgetting about PyPy, which has existed for almost 2 decades at this point?
RussianCow: That's a completely separate codebase that purposefully breaks backwards compatibility in specific areas to achieve their goals. That's not the same as having a first-class JIT in CPython, the actual Python implementation that ~everyone uses.
raddan: It's hard to say whether it's Windows related since the two x86_64 machines don't just run different OSes, they also have different processors, from different manufacturers. I don't know whether an AMD Ryzen 5 3600X versus Intel i5-8400 have dramatically different features, but unlike a generic static binary for x86_64, a JIT could in principle exploit features specific to a given manufacturer.
RussianCow: That makes sense if you're comparing with Java or C#, but not Ruby, which is way more dynamic than Python.The more likely reason is that there simply hasn't been that big a push for it. Ruby was dog slow before the JIT and Rails was very popular, so there was a lot of demand and room for improvement. PHP was the primary language used by Facebook for a long time, and they had deep pockets. JS powers the web, so there's a huge incentive for companies like Google to make it faster. Python never really had that same level of investment, at least from a performance standpoint.To your point, though, the C API has made certain types of optimizations extremely difficult, as the PyPy team has figured out.
hardwaregeek: For what it’s worth Ruby’s JIT took several different implementations, definitely struggled with Rails compatibility and literally used some people’s PhD research. It wasn’t a trivial affair
g947o: Money.
patmorgan23: Ooo this makes sense it's like if the Linux had don't break users space AND a whole bunch of other purely internal APIs you also can't refactor.
sheepscreek: I love playing with compilers for fun, so maybe I can shed some light. I’ll explain it in a simplified way for everyone’s benefit (going to ignore the stack):When an object is passed between functions in Python, it doesn’t get copied. Instead, a reference to the object’s memory address is sent. This reference acts as a pointer to the object’s data. Think of it like a sticky note with the object’s memory address written on it. Now, imagine throwing away one sticky note every time a function that used a reference returns.When an object has zero references, it can be freed from memory and reused. Ensuring the number of references, or the “reference count” is always accurate is therefore a big deal. It is often the source of memory leaks, but I wouldn’t attribute it to a speed up (only if it replaces GC, then yes).
yuliyp: what at all does this comment have to do with what it's replying to?
LtWorf: That is not the same thing at all, and not what he said.
JoshTriplett: It is exactly what I'm referring to. I didn't say there aren't still people around. But they're far enough behind CPython that folks like NumPy are dropping support.