Top
Best
New

Posted by f311a 21 hours ago

Python's experimental JIT to be removed(lwn.net)
490 points | 259 commentspage 2
phonon 19 hours ago|
https://github.com/facebookincubator/cinderx might be a better approach.
O5vYtytb 18 hours ago|
CinderX isn't generally faster unless you use "Static Python" which is a major change in how programs are written compared to typical python code.
phonon 17 hours ago||
Out of the box it's comparable to the current JIT, but yes, major gains are only possible with at least type annotations. But that may be the only real way forward for a JIT implementation for CPython with the ability to gradually speed up slow parts of large programs.

https://facebookincubator.github.io/cinderx/#performance

hedgehog 16 hours ago||
I did some experiments translating a typed subset of Python to C for small system use, certain features like lists of primitive types, generators and comprehensions, frozendict, simple classes, generic functions, etc, map with little or no cost but are so much cleaner than the equivalent code in plain C. You also get to write test harnesses using all the tools available to full Python. The main issue is unsurprisingly memory management, Obj-C / Swift style automatic reference counting works but has drawbacks, and it gets much more complicated if you want to mix the static and CPython code.

The static + AOT approach has a lot of promise now that type annotations are widely adopted, predictable behavior and good performance on code that is mostly idiomatic Python seem like a good alternative in many situations to the weight of Rust.

phonon 14 hours ago||
Yes, exactly. If you can get a 2-3x speedup in CPython just with type annotations, and then a possible additional 2-3x by dropping down to "Static Python," that may be an overall near optimal solution for the ecosystem, all things considered.
hedgehog 8 hours ago||
I didn't touch JIT (complexity and footprint way beyond what I can use or manage myself in any case) but the AOT path is pretty much what you'd get if you wrote naive C by hand. The emitted code is readable, in some cases you probably do better because more efficient algorithms are easier to code or reuse, but with the current refcounting that will have some overhead. I do want to try some ideas like supporting an @soa decorator for a List of DataClass type that keeps the visible interface but changes the memory layout. If someone wanted to sponsor tokens I could probably pure robot through a stage of fleshing out enough to port a few representative libraries and tune against the results.
pansa2 19 hours 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...

yxhuvud 18 hours ago|
Getting a JIT from underwhelming to actually good is always going to be a whole lot of iterative work to remove blocking parts of the existing implementation. In Ruby-land we have had a good JIT for a while now, but it took many release cycles and a ton of resources before it was able to outperform the non JITed version when using Rails. Don't expect quick fixes that make great strides and any investments in it needs to be persistent and apply over time.

It boggles my mind that it apparently is the case that such a popular language as Python isn't able to get the resources to do this.

ksec 18 hours ago||
It is more than that. CRuby have had multiple JIT attempt before YJIT landed. From what I can tell CPython didn't have that. And luckily enough we now have ZJIT replacing YJIT.
SuaveSteve 8 hours ago||
1. Python is slow, therefor we use C extensions. 2. We cannot make Python faster because of C extensions. 3. Go to 1.
Qem 17 hours ago||
Sad news, I put a lot of hope in this project. At least we keep the base interpreter improvements they brought along, and we still have PyPy. CPython JIT is dead. Long live PyPy!
tweakimp 19 hours 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 19 hours 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"

vovavili 17 hours ago||
The biggest winner from AI indeed appears to be Rust.
pjmlp 13 hours ago||
3GL code generation is only a transition step until models get more mature for direct machine code generation.

AI needs formal verification, not a borrow checker.

Retr0id 19 hours 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 19 hours 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?
jerf 18 hours ago|||
Rust is not your only option. Nor is it automatically the best option, though it is certainly a solid option for a certain set of requirements. Go is a pretty decent match for a Python rewrite; superficially it seems like you're giving up a lot but under the hood they're philosophically more compatible than meets the eye in a lot of ways. But any static language that you have some other local reasons to prefer is going to blow its socks off in terms of performance. And "blow its socks off" is just for the naive translation of a conventional Python code base over to a new language. If your codebase is amenable to threading and can take advantage of multiple CPUs somehow, the result may blow Python's socks off twice over.

The problem is that Python just isn't going to go fast. There are some languages that may have had more resources poured into them to make them go faster in absolute terms, like perhaps Java. But I don't think there's a single language that has had so many ways of trying to make it go faster given so much effort over so many decades. It's really time to call it... if you have Python code and it's a performance problem, if one of the many many many different solutions aren't adequate for some reason, Python is not going to get any faster than it is today and you're going to have to move off of it.

If you need high performance code, Python is simply not the right answer and you're going to have to skill up. Or accept what you have, which you'll have to decide if that's a viable option. If it's fast enough I don't advocate switching casually. But if it isn't, there isn't a realistic prospect that you're going to wake up in a year or two to a 30x-faster Python. I wasn't terribly convinced by that claim back in the early 2000s, but it hadn't really been tested yet. It has been tested now.

LtWorf 17 hours ago|||
Pypy is really fast. Have you tried it?
anthk 18 hours ago|||
RustPython it's pretty mature.
skeledrew 17 hours ago||
Not at all.

> RustPython is in development, and while the interpreter certainly can be used in interesting use cases like running Python in WASM and embedding into a Rust project, do note that RustPython is not totally production-ready.

- https://github.com/RustPython/RustPython

Yossarrian22 18 hours ago||||
You could try having it rewrite parts of the hot path into Rust with PyO3.
skeledrew 17 hours ago|||
There are already many solutions to the performance issue from which you can pick. You don't need to understand the C in numpy to use it for example. And I'd say it's highly unlikely that you have a use case that, if it's applicable, isn't already addressed. Like it's generally pointless to optimize language performance for code that's doing a lot of network operations, because network lag will always dwarf such optimizations.
mahboi 8 hours ago||
There's so much Python code that uses numpy etc but still ends up having some hot part in Python that's nontrivial to translate to something faster. Same reason people get frustrated with the GIL.
lemagedurage 19 hours 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.
Retr0id 18 hours ago||
This works well if there are obvious hot spots that can be easily isolated, but sometimes the perf issues are more uniformly distributed throughout a codebase.
samus 17 hours ago|||
Mature projects simply don't like large unexpected code drops if it is not made clear beforehand what the blast radius is and how it is going to be maintained. On top of that it seems that the performance gains weren't as expected and require further invasive changes.

Implementation effort has never been what has held these efforts back. LLM helps with squirting out code, but the hard tasks are benchmarking, profiling, community engagement, knowledge management, and dealing with the hard questions such as whether the change is actually worth the additional complexity.

These concerns won't go away even if we give up on human developers being able to grok the code and instead completely relying on LLMs for coding.

pjmlp 18 hours ago||
We pick languages that embrace machine code like Julia, Mojo, Common Lisp, Scheme, and stop calling libraries that are written in C, C++, Fortran, Rust, "Python Libraries", when they are thin bindings.

Clearly the community doesn't want PyPy, GraalPy, or even a CPython JIT.

snovymgodym 13 hours ago||
It clearly isn't hurting Python's popularity, but man the performance of the reference implementation is embarrassing.

V8 made JavaScript fast in 2008, soon that will be 20 years ago.

Perhaps I live in a bubble, but so much of the production Python code I see is fully type-hinted and makes used of an aggressive linter & type checker to the point where it might as well be written in Go/C#/Java/TypeScript so that it can actually take advantage of the performance gains instead of being loaded into a runtime that turns everything into heap-allocated PyObject pointers.

cpburns2009 13 hours ago||
This is exactly how I write my Python. I'm currently debating between going in deep and transitioning to either TypeScript or Rust. Go's object system and error handling is too weak. Java is too verbose, but I have a soft spot for it.
seabrookmx 4 hours ago|||
C# is worth a look if you want less verbose Java with async/await like you have in other languages, and better performance than Typescript.
pjmlp 13 hours ago||||
Modern Java is not that verbose, plus you can use Scala, Kotlin, Clojure instead.
throwaway7783 11 hours ago|||
New java is not very verbose.
_old_dude_ 12 hours ago||
If you want V8 like optimizations, you have to introduce a strict mode.

Python interpreter is known to leak its implementation (__class_ modification after creation, monkey patching with __getattr__, sys._getframe, eval/exec, deterministic call to __del__, no proper python API for libraries, etc.)

You have to plug all of those holes before having a chance to get a decent JIT. Otherwise it will be just another JIT attempt, like Psyco, Unladen Swallow, Pyston.

snovymgodym 10 hours ago||
Python is not uniquely dynamic to a degree that would prevent an efficient implementation.

V8 predates strict mode, and handles all the exec/eval, monkey patching and object system abuse you can do in JavaScript just fine. Common Lisp is one of the most dynamic languages in the world and allows you to do ridiculous things in terms of meta-programming and essentially building domain-specific languages into your program, yet it too manages to have ahead-of-time compiled implementations that are very performant. Also PyPy exists.

There are definitely some technical aspects that make it hard to make Python fast, but they are not insurmountable. The reason CPython is slow today is simply because performance has not historically been prioritized by its developers.

btown 19 hours 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.

skeledrew 17 hours ago||
Python use is widely diverse. Anyone wishing to contribute to that which is published to such a diverse community, all of whom expect Python to continue working for them without any regressions, has to be ready to cater to that diversity in its entirety.
lemagedurage 19 hours 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
v3ss0n 14 hours ago||
They should had just port everything to pyPy.
bilsbie 19 hours ago||
What’s the latest on getting rid of the GIL? Did that work out?
LtWorf 17 hours ago|
It did. It's slower though.
genxy 16 hours ago||
And you get it back with threads, which can now scale.
LtWorf 12 hours ago||
I didn't need compute threads. Just I/O threads. So now it's just slower.
niltecedu 15 hours ago|
ffffffff.... damnit I love python but why is it so difficult like this. JIT would have been so perfect so the language, increasingly overtime with AI code coming through I am not sure not focusing on making the performance better is going to be better for longer term. Even though a lot of the other operations done in python are done faster in libraries I would still like faster startup times, or faster loops.
More comments...