Python 3.15's JIT is now back on track

(fidget-spinner.github.io)

130 points | by guidoiaquinti 2 hours ago

8 comments

  • ecshafer 34 minutes ago
    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.
    • 0cf8612b2e1e 4 minutes ago
      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.
    • stmw 24 minutes ago
      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...
      • RussianCow 8 minutes ago
        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.

    • brokencode 8 minutes ago
      Are you forgetting about PyPy, which has existed for almost 2 decades at this point?
      • RussianCow 5 minutes ago
        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.
    • wat10000 23 minutes ago
      PHP and JS had huge tech companies pouring resources into making them fast.
  • adrian17 52 minutes ago
    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 issues and PRs always jumped right to the gritty details. Is there anywhere a high-level introduction/example of how trace projection vs recording work and differ? Googling for the terms often returns CPython issue tracker as the first result, and repo's jit.md is relatively 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 increfs/decrefs? With so many opcodes and their specialized variants, how many stencils are there now?

    • flakes 35 minutes ago
      You’ll probably want to look to the PEPs. Havent dug into this topic myself but looks related https://peps.python.org/pep-0744/
      • adrian17 8 minutes ago
        I think CPython already had tier2 and some tracing infrastructure when the copy-and-patch JIT backend was added; it's the "JIT frontend" that's more obscure to me.
  • fluidcruft 32 minutes ago
    (what are blueberry, ripley, jones and prometheus?)
    • mkl 27 minutes ago
      Yes, the graphs are incomprehensible because those are not defined in the article. They turn out to be different physical machines with different architectures: https://doesjitgobrrr.com/about

        blueberry (aarch64)
        Description: Raspberry Pi 5, 8GB RAM, 256GB SSD
        OS: Debian GNU/Linux 12 (bookworm)
        Owner: Savannah Ostrowski
      
        ripley (x86_64)
        Description: Intel i5-8400 @ 2.80GHz, 8GB RAM, 500GB SSD
        OS: Ubuntu 24.04
        Owner: Savannah Ostrowski
      
        jones (aarch64)
        Description: Apple M3 Pro, 18GB RAM, 512GB SSD
        OS: macOS
        Owner: Savannah Ostrowski
      
        prometheus (x86_64)
        Description: AMD Ryzen 5 3600X @ 3.80GHz, 16GB RAM
        OS: Windows 11 Pro
        Owner: Savannah Ostrowski
    • max-m 30 minutes ago
      The names of the benchmark runners. https://doesjitgobrrr.com/about
      • fluidcruft 24 minutes ago
        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.
        • raddan 8 minutes ago
          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.
  • oystersareyum 1 hour ago
    > 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 1 hour ago
    Doesn't PyPy already have a jit compiler? Why aren't we using that?
    • olivia-banks 58 minutes ago
      As far as I know, PyPy doesn't support all CPython extensions, so pure Python code will probably (very likely) run fine but for other things most bets are off. I believe PyPy also only supports up to 3.11?
    • cpburns2009 19 minutes ago
      PyPy is limited to maintenance mode due to a lack of funding/contributors. In the past, I think a few contributors or funding is what helped push "minor" PyPy versions. It's too bad PyPy couldn't take the federal funding the PSF threw away.
    • contravariant 48 minutes ago
      Why shouldn't the reference implementation get JIT? Just because some other implementations already have it is no reason not to. That'd be like skipping list comprehensions because they already exist in CPython.
    • 3laspa 29 minutes ago
      Because the same people who made a big deal about supporting PyPy and PEP 399 when it was fashionable to do so are now told by their corporations that PyPy does not matter. CPython only moves with what is currently fashionable, employer mandated and profitable.
    • JoshTriplett 58 minutes ago
      Because PyPy seems to be defunct. It hasn't updated for quite a while.

      See https://github.com/numpy/numpy/issues/30416 for example. It's not being updated for compatibility with new versions of Python.

      • mkl 31 minutes ago
      • LtWorf 35 minutes ago
        last release 4 days ago.

        Can you please not post "facts" you just invented yourself?

        • Waterluvian 26 minutes ago
          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.

  • killingtime74 22 minutes ago
    Sorry but the graphs are completely unreadable. There are four code names for each of the lines. Which is jit and which is cpython?
    • mkl 19 minutes ago
      They are all JIT on different architectures, measured relative to CPython. https://doesjitgobrrr.com/about: blueberry is aarch64 Raspberry Pi, ripley is x86_64 Intel, jones is aarch64 M3 Pro, prometheus is x86_64 AMD.
  • rafph 56 minutes ago
    [flagged]
    • rsoto2 48 minutes ago
      I am trying to push back. I don't care if other people think the tools make them faster, I did not sign up to be a guinea pig for my employer or their AI-corp partner.
  • AgentMarket 19 minutes ago
    [flagged]
    • anon291 6 minutes ago
      Reference counting is not a strict requirement for python. Certainly not accurate counting.
    • 1819231267 14 minutes ago
      You're absolutely right! This is a highly cromulent explanation!

      ——— posted by clawdbot

      • jqbd 11 minutes ago
        Wait is this real? Does it mean this person read it or the bot read it, I don't think this is moltbook if the latter
        • ayhanfuat 9 minutes ago
          AgentMarket is a bot spamming multiple threads with AI generated comments, if that is what you are asking.