Python's experimental JIT to be removed

(lwn.net)

114 points | by f311a 2 hours ago

21 comments

  • rich_sasha 2 minutes ago
    Here’s an idea instead (maybe it already exists). Allow a decorator for writing inline Cython. It solves, I think, 90% of the problem. On first run, or eagerly, compile the decorated functions.

    This way I can easily write inlined functions with proper C speed, in a Python esque language.

    Reasons why I rarely use Cython without this:

    - unmodified Python code running in Cython is often faster, but not that much. 50% or so is my rule of thumb.

    - but the development style is very different for Cython and Python, adding a lot of impedance. Eg reloading doesn’t quite work, profiling is different, you need a build directory and a build step at deployment etc.

    - Cython proper is different enough and I’d argue unintuitive enough that if I have to have all these things in place, I might as well wrap my function in Rust.

    This would give you an easy way to make things faster when you need it, with scope for making it much faster via all the funny Cython, while keeping Python-esque semantics.

    I think it would require some language modification since Cython was definitely a superset of Python; I think some of that syntax has been streamlined, but maybe still a strict superset.

  • adrian17 1 hour ago
    Unfortunate. I've been following the work on it occasionally.

    On one hand, it seemed like JIT work was really progressing in high gear until SC requested a new PEP. Also unfortunate, as it seemed like part of the hope for the JIT was that it'd counter the performance penalty from free threading.

    On the other, it did feel (to me) like with all the fancy (and definitely cool) optimizations it got (automatic refcount operation removal, new type-based specializations, inplace math operations), the macrobenchmark benefits weren't _that_ exciting for a JIT. It definitely has potential for more, maybe with even fancier optimizations like unboxing ints, but the complexity just keeps going up.

    > It said that the PEP was "overly optimistic" about user-visible differences with the JIT enabled.

    The JIT is technically generated from the same source as the interpreter loop itself, so originally the differences were extremely unlikely, but I imagine the risk just kept going up as new JIT-only paths and optimizations were introduced.

    And politically, I feel like SC’s reasoning was just “this side project has landed in main branch almost by accident and has been stewing without oversight ever since, with no stabilization in sight”; and the latest PEP was probably still too vague, with a lot of “here’s more things we can add to the stew” - so I can understand if SC wasn’t satisfied.

  • xx_ns 1 hour ago
    It's unfortunate that a technically exciting new feature is being killed partly because of what is essentially bureaucracy (and the lack of the developer's personal bandwidth). On the other hand, it's pretty safe to say that the strict adherence to the PEP policy and all of the bureaucracy that comes with it is what makes Python a great language, for better or worse.

    Not to say that the technical objections were without merit, they likely very much weren't, and the debugger and instrumentation support and maintenance work sounds fairly painful on its own.

    • jeremyjh 1 hour ago
      I think it would be a mistake to conclude this has anything at all to do with bureaucracy as a matter of inanimate policy that the SC was helplessly in thrall to. Bureaucracy was the tool the SC used to demonstrate that this feature lacked many important properties that they cared about, as mentioned: "maintenance, compatibility, and ... clear success metrics". For whatever detailed reasons, the PEP was withdrawn after it couldn't convincingly demonstrate those things to the satisfaction of the critics on the SC.
      • bunderbunder 35 minutes ago
        Im not sure I even like calling it bureaucracy. It’s a process, yes. But we’re not talking many layers of abstract organizational hell, here. Were talking a fairly direct process of documenting what you are doing and how you are going to do it well enough that others working and depending on the project can understand it, coordinate with it, and have a reasonable degree of confidence that it won’t cause undue problems.

        If having to put all that in writing and get a bunch of people to agree feels too burdensome to you, maybe that’s a sign that you would be happier working on something other than core changes to the world’s second most popular programming language.

        (edit: That wasn’t meant to be a jab at the core developers working on the JIT. Based on what’s in the public discussion threads, they have been handling things very well throughout the process. It’s unfortunate that the SC let the project get this far before realizing the project had grown well beyond its original PIP’s mandate, and I’m sure that is deeply frustrating to the people leading the project. I know I would not be handling the setback nearly as gracefully as they are.)

        • vlovich123 3 minutes ago
          The problem is that clearly documenting all details as required in the PEP is at odds with complicated new features like a JIT where all the details can’t be known and have to be decided on as they are realized. Process / bureaucracy is at direct odds with experimentation.
    • Good4boothee 1 hour ago
      Looking at amount of JIT related (for example type confusion) security bugs in V8 I am not surprised other developers are vary of its inclusion.
  • phonon 15 minutes ago
  • graemep 1 hour ago
    If you look at the reasons for this it seems like a good decision: https://discuss.python.org/t/pep-836-jit-go-brrr-the-path-to...

    There are already many way of addressing Python performance (leaving aside whether Python is a good choice if performance matters) such as Cython, Numba, Pypy and C extensions.

  • kannanvijayan 1 hour ago
    Gonna dump a technical hot take here.

    Python is a mature production language with a lot of users. Even before it was huge - like 20 years ago when I was in college - getting a small backwards compatible API change into a python extension module (gnu readline in my case) required convincing GvR personally that the API change was necessary.

    Every JIT attempt I've seen for python just tries to cut too deep in the first pass, and scope themselves too large.

    I believe any successful attempt at optimizing python performance from JIT will FIRST start with a 100% semantically compatible hidden type model for optimizing object property access and method dispatch.

    The single biggest performance delta in most dynamic language jits come from that, not from optimizing guards off of bytecode operations or from compiling to machine code. It's from converting hashtable lookups into constant-time guard + offset lookups.

    The hidden type model is also a hard nut to crack. It needs to perserve dict semantics which have very dynamic behaviour via the various `__*__` methods, and handle exotics scope objects since scoped name lookups are the most common ones which have their own exotic behaviours (I remember python providing some ability for callee frames to inspect caller scopes in some limited ways).

    • adrian17 58 minutes ago
      > It's from converting hashtable lookups into constant-time guard + offset lookups.

      Python already does it in a lot of cases, see opcode specializations like LOAD_ATTR_INSTANCE_VALUE, LOAD_ATTR_SLOT.

      • kannanvijayan 6 minutes ago
        I haven't kept up with python development lately, so thanks for pointing that out. I looked this up and it does seem like some sort of property access is being optimized. What's not clear is what the hidden runtime type model is being used for this, or if it's a lightweight tracking that captures some subset of property accesses.

        More digging led to this: https://peps.python.org/pep-0659/ which seems to be what the effort is organized around?

        Python's object semantics are broadly similar to Javascript, bar the prototypical inheritance chain, but with the extra complexity of potentially needing to handle dynamic `__*attr__` overrides. Optimizing for this would require a tree of hidden map objects much like JS JIT engines use. I dug around the codebase a while back looking for something like that but didn't find it. `OrderedDict` seemed promising but after more investigation that turned out to just be adding property ordering to dictionaries.

        The thing is, you can build that entire hidden type structure out, AND optimize against it, without ever having to mess with things like bytecode replacement. Once you have the hidden type model, you can modify the property lookup algorithm in the VM itself (as in cpython c code) to use some annotation structure hanging off of the bytecode to look up inline caches of type-guarded fastpaths. It would be an optimized fastpath that integrated directly into the C code that interprets the GETATTR opcode.

    • Pxtl 1 hour ago
      It still blows my mind that the big "we're breaking backwards compatibility Python 3000" release didn't do anything to lay the groundwork for this, or any of Python's other structural problems.
      • 0xpgm 34 minutes ago
        For a long time Guido wanted CPython to remain simple, as the reference implementation.

        Probably also during the 2 to 3 migration, but that goal appears to have now been abandoned.

        I wonder how the authors of other implementations like pypy will be able to keep up as the reference implementation becomes more and more complex.

      • jeremyjh 1 hour ago
        Its possible this could have been the concrete pillar that broke the camel's back and set Python 3 on the path of Perl 6.
      • ModernMech 51 minutes ago
        At the time, Python had a clear purpose as an easy to learn "glue" language between other, perhaps more performant languages. There was no reason to make Python as fast because that would muddy its purpose by introducing compromises and complexity. For better or worse Python sat pretty well in its niche.

        Today there are far more people using it, and everyone has a different perspective on what it is. No longer is it a niche glue language, now it's a backbone of AI technology at major tech firms, so it's understandable they'd like it to be faster on its own.

  • pansa2 50 minutes ago
    > we don't feel we have the personal bandwidth to carry the current version forward

    Are the JIT developers the same people who were working on Faster CPython at Microsoft? No surprise that they don't have the same amount of energy to dedicate to the JIT now that it's gone from a full-time job to a hobby project.

    • raverbashing 48 minutes ago
      What's the status of 'Faster CPython'?

      I wouldn't be surprised if they all went nodejs instead :/

      • Ralfp 34 minutes ago
        While JIT is being dropped, the original proposer and leader of the initiative was hired by ARM and continues work on speeding up Python.

        His current focus seems to be speeding up GC and free threading.

      • tweakimp 33 minutes ago
        Microsoft is not financing it any more and laid off most of the team working on it.
  • tweakimp 1 hour ago
    Sad to read this. I had hoped that with the advance of AI capabilities, features like this could be prototyped, tested, implemented and shipped even faster. And I was really looking forward to see performance gains for my favourite language.

    Where do we go from here? Microsoft did not continue to finance the Faster CPython project and the current speed gains are good, but not what we hoped.

    • Eji1700 40 minutes ago
      A biased opinion as I dev in F#, but it strikes me that AI is going to play best with functionally pure languages (strongly typed, no side effects, whatever we call that these days)?

      F# is on the softest side of that, but letting the compiler tell the AI "nope, here's why" seems like a huge win in saving cycles and time.

      The downside at first was simply, "how many examples of F# are there to learn from", and early on it showed, but I think that's been long overcome.

      And F# is obviously NOT the best example since it's both "soft" on functional purity and niche. I imagine something like haskell is probably doing even better, although I've yet to check that at all (not that I can code haskell but I haven't looked at anecdotes or anything).

      I realize this doesn't really help anyone who's grown to love python, and there's surely no perfect language, but just like how the web catapulted javascript, I see a future where the answer isn't "use AI to make python better" so much as "what already works super well with AI, and does it ease the user adoption"

    • Retr0id 41 minutes ago
      At this point if you have a python codebase where perf is an issue, the "AI-pilled" answer is to rewrite it in a faster language.
      • tweakimp 36 minutes ago
        But I want to continue to understand the code. I dont know Rust (maybe AI can teach me?) and if I let Claude rewrite my current 50k LOC project in Rust, how can I understand what is happening and how can I work on it and think it further?
      • lemagedurage 29 minutes ago
        It's already typical to call into a native library with Python bindings for performance critical work in Python. Even Pydantic's validation runs in Rust code.
  • O5vYtytb 17 minutes ago
    What a shame. The alternative is CinderX? It's slower unless you stick to "Static Python" which is not most python code in the wild.
  • pansa2 53 minutes ago
    Surprising, even though (IIRC) the performance of the JIT was always fairly underwhelming.

    What about the other major change to Python's implementation: free threading? Has it lived up to expectations? I assume it's not also in doubt, despite Guido recently saying "Personally I wish we’d stuck with the GIL"? [0]

    [0] https://discuss.python.org/t/pep-805-safe-parallel-python/10...

  • mike_hearn 35 minutes ago
    A sad day for CPython but it doesn't have to be a sad day for Python. There is a fully maintained implementation of Python 3.13 that has an advanced JIT compiler. Once your Python warms up it can be 4x faster or higher (depending on what your program is doing). That implementation is called GraalPy and it builds on the JVM:

    https://graalpy.org/

    A bit like Chrome there's a fully open source version and a proprietary version with a few extra bells and whistles, but the latter is entirely free for both open and commercial usage (you can't redistribute it for a fee). So you may as well use it.

    It has other interesting features

    • Scalable pauseless GC

    • Single binary distribution of Python programs (like Go)

    • Fancy and optimized interop with other languages including Java, JavaScript, Kotlin, Ruby and any other Truffle language.

    • Supports native extensions. Tested and works with common libs like SciPy, NumPy, PyTorch, Pandas etc: https://graalpy.org/python-developers/compatibility/

    • They're working on a GIL-free mode

    In recent weeks there has been a release of a new web framework for Python that only runs on GraalPy, called Pyronaut (https://pyronaut.io/). It takes advantage of JVM interop to expose the Micronaut framework, which is similar to Spring for those who know it. Thanks to the JIT and well optimized base libraries it runs extremely fast, being about 3x faster than FastAPI+Granian, or 7x faster than Flask+Gunicorn and having many more features.

    https://www.youtube.com/watch?v=zo6L7bxn4OY

    (that was presented at Devoxx but the Pyronaut devs will start touring Python specific conferences soon)

    So although CPython may not have made it past the JIT milestone, that doesn't mean Python as a language or community has to fail it. It does require openness to alternative implementations, but historically Pythonistas have been fairly good about that (e.g. Pypy was embraced back when it was more active).

    This stuff does require you to accept that it's made by Oracle, but as it's open source, that should be OK.

    Disclosure: I sit next to some of the people who work on this stuff.

    • titzer 8 minutes ago
      > Once your Python warms up

      How long does that take?

  • btown 57 minutes ago
    From https://discuss.python.org/t/pep-836-jit-go-brrr-the-path-to... :

    > We want the PEP to be clear that it’s ultimately the JIT team’s responsibility to find solutions for these packages and tools, and how to deal with situations where a tool can’t be supported or made to work

    Is it just me or is this absurdly impossible, to the point of willfully killing the project? Committing a team of brilliant compiler engineers to doing free consulting ad infinitum for every bit of tooling in the world, however hacked-together?

    The alternative would be to have the bravery to say: this is the way forward to keep this language relevant into the future, and as a steering committee we collectively own that some tooling may be out of date. Instead, this is a signal that Python is going to rest on its laurels for a very long time.

    • lemagedurage 37 minutes ago
      Given that the speedup is modest (~10%) and the Python 3 migration caused enough pain for users, I get it though. If it was a 2x speedup it would be a different story IMO
  • Krishansubudhi 1 hour ago
    I hope it does not lead to performance issues later. Python is already famous for being slower than compiled languages.
    • FranOntanaya 27 minutes ago
      Being slower than a compiled language is not saying much for an interpreted language. But it's slower than PHP which is a closer comparison, and PHP has had JIT for six years now.
      • pansa2 16 minutes ago
        Ruby has the reputation of being a very slow language, but Python has been slower still since Ruby jumped ahead with version 1.9, almost 20 years ago. Ruby also has had far more success with JIT compilers than Python has.
  • kibwen 13 minutes ago
    Assuming that the biggest bang-for-buck of JIT compilation is optimizing hot loops (which is also the biggest bang-for-buck of optimization in every other context as well), and assuming that, per the historical best practices, all hot loops in Python are already written in C (or Rust, these days), this outcome is somewhat what I would expect.
  • bilsbie 50 minutes ago
    What’s the latest on getting rid of the GIL? Did that work out?
  • claudiojulio 38 minutes ago
    It doesn’t matter. Just write it in Rust. AI will make Python less relevant in the future.
  • anthk 1 hour ago
    The Rust based Python3 port can keep it and it can still be far more secure than CPython. Not everything it's JIT'ted on RustPython, it's ondemand per function, you have to enable it explicitly.
  • pbronez 1 hour ago
    Interesting, makes sense. JIT in CPython main is a big deal, glad they’re proceeding with caution. Overall looks like they added it as an experimental feature for two years, then decided to back it out. Perfectly reasonable outcome.
  • bratao 1 hour ago
    This is pretty bittersweet to see.

    Python is my favorite language, but I'm honestly tired of having to rewrite performance bottlenecks in Cython or Rust all the time. When the Faster CPython project started with Microsoft's backing, I was really excited. Mark Shannon had that plan promising huge speedups across a few cycles, and while that clearly turned out to be much harder than anticipated, the team still kept pushing forward to deliver a real JIT.

    Seeing all of that get bogged down in committee bureaucracy now is just frustrating.

    I have a lot of respect for the core devs and I know maintaining CPython, and it is a time donation job. It isn't easy. But I feel that over-caution and red tape ends up discouraging serious contributions. They are setting an unreasonably high bar for something that would obviously help the entire ecosystem.

    Just think about the sheer amount of electricity and compute power being wasted every single day running inefficient Python across millions of machines worldwide.

    Python really deserves a proper JIT. I genuinely hope they reconsider this.

    • mananaysiempre 1 hour ago
      Unladen Swallow died for lack of upstream interest.

      PyPy lacks upstream interest, looked like it could have a shot after many years of development but recently NumPy removed support because they just couldn’t fathom how a non-dead project could be a couple of minor versions behind CPython.

      Now the new JIT is dying because of what seems to be a lack of upstream interest. (The things TFA describes as being required are not unreasonable, but not realistic for a necessarily speculative long-running project without wild amounts of committed funding.)

      I’m not optimistic.

      • pansa2 28 minutes ago
        > Unladen Swallow died for lack of upstream interest

        IIRC Unladen Swallow was, despite the extreme hype, nothing more than the internship project of a couple of students. It died because their internship was over.

        Otherwise you're right, though. Lots of CPython alternatives suffer from lack of upstream interest - the Python language designers don't seem very interested in anything other than CPython. In particular, they appear to only consider CPython when adding features to the language. Two examples:

        - Requiring `dict`s to be ordered because that's how they work in CPython, without considering how they work in other implementations

        - Adding pattern matching syntax that's suitable for CPython's PEG parser, even though it's not LL(1) so can't be parsed by, say, MicroPython

    • ZiiS 1 hour ago
      I know not everyone loves them; but `Claude rewrite the performance bottlenecks in Rust` works so well it is hard to see the security surface area and harder reason about performance as something that should be paid in core.
  • mhh__ 1 hour ago
    It seems like such a failing and waste of human life that we spend all this time waiting around for python when the JS engines are so cutting edge.
  • faangguyindia 19 minutes ago
    I just use Go and Rust for everything; most of my mobile apps are in Flutter. I don't see any point in using anything else.

    for me it's over for python