Hacker News
points by adrian17 2 days ago | 0 comments
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.

[–] cogman10 2 days ago
I think this is a major issue with requiring a PEP for what's a performance optimization.

JITs are big nasty things that by their nature have to do a lot of things. You are basically saying "Give us a PEP for a new python interpreter and compiler".

What they do is fuzzy by their nature because optimizations are very rarely universally beneficial. It's a game of measuring, looking for regressions, and tackling the biggest problem next for whatever sample applications you have available. You always run into the risk of overfitting on top of all that (You may have made django faster, but you've made flask slower).

This is the sort of thing that, IMO, should not go through the PEP process. It's an implementation detail for the runtime.

Imagine, for example, if the JVM needed a bunch of JEPs for JIT improvements. They'd never get done. Or if any javascript engine needed ECMA acceptance before they could do a new JIT optimization.

[–] stickfigure 2 days ago
> Imagine, for example, if the JVM needed a bunch of JEPs for JIT improvements.

They do:

https://openjdk.org/jeps/197

https://openjdk.org/jeps/515

Not every optimization requires a JEP, but certainly something as big as "add or remove a JIT" would 100% require a JEP.

[–] adrian17 2 days ago
> Imagine, for example, if the JVM needed a bunch of JEPs for JIT improvements.

FWIW, I definitely can find a bunch of both PEPs and JEPs for internal optimizations, random examples:

https://peps.python.org/pep-0509/

https://openjdk.org/jeps/147

[–] cogman10 2 days ago
You can find those JEPs, but frankly they are there for 1 of 2 reasons.

1. An outsider to the regular OpenJDK dev team proposing an optimization.

2. Advertising for a cool new performance tweak with potentially large impact.

You'll also notice that the JEP descriptions are very different from PEP descriptions.

Probably the largest JEP for the JVM, Valhalla

https://openjdk.org/jeps/401

Does not have the same level of requirements being asked of the Python JIT. Further, it's well understood that this JEP will "live on main" for quite some time in preview before it's accepted and merged.

What the JEP does, instead, is simply describe the feature and potential risks.

The vast majority of JVM optimizations do not get a JEP.

[–] adrian17 2 days ago
Fair, I don’t argue with that, I’m not knowledgeable about Java’s processes. Just one thing:

> The vast majority of JVM optimizations do not get a JEP.

In Python too. Still, the JIT really is just a really big thing. I don’t know if there could be a better way to do it, as either 1. You develop it off-branch and… make an enormous PR when you’re done, with risks of getting rejected anyway? Or 2, you allow more experiments on main like Rust, but then you end up with hundreds of minor half-maintained nightly-only features, possibly conflicting with each other, and eventually go through bureaucracy to remove them anyway.

[–] cogman10 2 days ago
So, I'd grant that it'd probably be a JEP for java (the initial JIT) but not that every change to the JIT would result in a new JEP. Java's JIT, hotspot, was integrated right before they started the JEP process. The JEP for the JIT would likely be pretty boring like "It's a JIT, it does this, in some applications we see this sort of speed up". Much like the AOT JEP https://openjdk.org/jeps/514

The Java governance allows for a lot more open ended projects with follow ups. Not that it's reckless, Valhalla is proof of that, but rather that once something is good enough they are pretty open to just shipping it as a preview feature and refining until it is worthy of being stable.

That's why, for example, we saw ZGC get merged, and then JDK after JDK seeing continuing development and improvement on ZGC (Or G1 for that matter). These GCs were fairly rough on their first release and now they are pretty much best in class.

I see a Python JIT as the same thing. Delivering the infrastructure for a JIT would need a PIP, but I wouldn't put in things like "acceptance criteria" beyond "doesn't break older code". I would expect such a project to get continual updates without PEPs.

[–] adrian17 2 days ago
> I would expect such a project to get continual updates without PEPs.

Just for completeness: the original JIT PR was merged quite enthusiastically and only after the fact it was pointed out that it should have went through a PEP process [1]. The following PEP 744 was of the “informational” type, and the just-withdrawn PEP 836 was the first “standards track” PEP, which means that (in my understanding) it’s technically the first actual PEP that the SC would formally comment on. So in a way it’s not “can we update the JIT” PEP, but the first real “does SC want this JIT as proposed” PEP.

That said, I do agree with most of what you said, especially the acceptance criteria part.

The issue I have and find it hard to resolve is that since the code was already on main, the feature was already in “sunk cost” mode. It’s hard when the code is already on main and another 3 optimization PRs are always there behind the corner, but it needs to be possible for SC to say “we decided it’s not actually worth all this complexity for <some small number>% speed improvement” (I’m not commenting whether in this particular case it’d have been a right call), and the PEP (if not withdrawn) was the way to exercise that control.

[1] https://github.com/python/cpython/pull/113465#issuecomment-1...

[–] pjmlp 2 days ago
The original JIT certainly did not get a JEP, because JEPs replaced the previous JSR process.

And even then, Hotspot did not got a JSR, because all that work was done before Sun started collaborating with industry partners for Java evolution.

They "simply" ported the JIT compiler from the Strongtalk acquisition into Java.

[–] crabbone 1 day ago
Oh, it's not just a performance optimization. But you've said it yourself: "a new python interpreter and compiler". A lot of Python code out there lives with assumptions of CPython interpreter built into it. Pretty sure pytest would've been affected, should JIT replace the existing interpreter, for example.

Anyways. I don't believe that Python needs a JIT compiler. I don't believe that CPython can realistically replace its interpreter with JIT compiler without causing major problems with the community packages.

The way I see it: Python users today desperately want Java. They want it called Python because there's some vague memory still around of Python being cool and Java not being cool.

In Russian there's a children tale about a hungry soldier returning from a war and a greedy old woman who offered him a bed for the night. The old woman then pretends to have no food for dinner, and a soldier promises her a magic trick of making a porridge out of a hatchet. And so he tells the woman to put a pot on a stove with a hatchet in it, and step by step he makes her add all the ingredients necessary to make a porridge to the pot. The story gave birth to the idiom "hatchet porridge", which is used to describe anything that was created in a similar way: by deception, when another goal was allegedly being pursued.

So, to me, the current state of Python is this "hatchet porridge". None of its users want the actual Python (the hatchet is still sticking out of the pot), and they keep adding Java ingredients to the pot in hopes to cook up Java. And so was JIT. It just turned out to be too difficult to throw away the hatchet. An the porridge still has some chipped wood in it as well as a metallic taste.

[–] riffraff 1 day ago
Just FYI, basically the same story is common in European folklore, and there's a somewhat idiomatic "stone soup" concept in English

https://en.wikipedia.org/wiki/Stone_Soup

[–] mcepl 1 day ago
Aren’t you confusing internals and API? I don’t think nobody cares about HOW the optimisation is done, but SC wanted API with the rest of the interpreter be defined and stable. Two different things. I think.
[–] lenkite 2 days ago
I am confused. Why can't they have an experimental, optionally-enabled feature for a few years while they iron out all the issues ? What is wrong with that ? The JDK keeps doing this all the while. They write a new JEP if there are changes across previews.
[–] cedarbyte482 1 day ago
I also dont get it
[–] bjourne 2 days ago
> 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.

Zero chance of shoehorning that into a standards-compliant Python runtime. Some things are too fundamental to change without affecting the user-visible language: JITting, lazy imports, threading, copying gc, ref counting, etc.

[–] ActorNightly 2 days ago
I mean, I have had great success with prototyping stuff in python, then letting an llm translate it to C. My 3090 with Gemma4:31b does this very well with a few guidelines.

Dunno how much investment is needed into language optimization anymore.

[–] 14113 2 days ago
That works well for greenfield code, but if working on compiler optimisations has taught me anything, it's that there is a lot of legacy code out there in the world that would benefit from re-compilation with optimisations - but would be very difficult to re-write for speed (regardless of whether the work is done by a human, AI, or other machine tool). JIT compilation fits very nicely in this niche, as it means that existing Python projects can get (theoretically) better performance without re-writing.
[–] grep_it 2 days ago
I've had good success with just using mypyc (https://mypyc.readthedocs.io/en/latest/introduction.html) on typed python code.
[–] nomel 2 days ago
> on typed python code.

A fairly massive undertaking for existing code, which jit was supposed to be useful for.

[–] EdwardDiego 2 days ago
You can use static type analysers and runtime type profilers to add type annotations to a legacy codebase, but the interesting bit would be if you're built on top of a large untyped codebase you don't control like, say, Django, how far it can go.
[–] zahlman 2 days ago
I would imagine that the LLM has a much easier time adding correct type annotations to old Python code than it does translating it to C.
[–] EdwardDiego 2 days ago
In my experiments with this, maybe, sorta, it'll do some AST stuff then it'll go "dang this shit is dynamic AF" then suggest a static type inference tool, then a runtime type profiler.

Which honestly, is the right approach.

[–] lenerdenator 2 days ago
People have been calling Python a "prototyping" language for decades. I'd be interested to see how many Python projects ever actually get rewritten in a more performant language. My guess is, up until the last five years that was almost never done. Even with LLMs to help, is that the best use of your tokens and humans' time? It doesn't add a feature. It could conceivably cut costs after enough time, but only if done correctly.
[–] zahlman 2 days ago
> My guess is, up until the last five years that was almost never done.

Because having just the hot loop in the performant language is often deemed good enough. And there's tons of Python code out there where the "hot loop" is already automatically in C (the various operations implemented in C by the runtime) or where you can get close enough e.g. with Numpy. Consider that things like Pygame can exist; for a lot of the games people want to make, the only thing that really needs to happen anywhere near "bare-metal" speed is blitting.

[–] ActorNightly 2 days ago
> My guess is, up until the last five years that was almost never done.

It was done plenty. Just with extensions to python like numpy and opencv. There is no reason to translate everything versus just the critical pieces.

[–] nrawe 2 days ago
Doing it currently, Python to Go. Early indications are a 50-98% increase in speed (e.g. one testcase went from 26hrs to 30mins) for network/CPU heavy workload. Conversion via Qwem, lots of testing needed but compute savings will be worth it.
[–] mynegation 2 days ago
Did you mean “50-98% decrease in running time”? Just calculating from your 26hrs to 30 mins seems to imply so. In terms of speed that translates to 100% to 5100% increase in speed.
[–] nrawe 1 day ago
Yes, sorry, typing fast - we knew Go would be faster but not quite on that scale.
[–] mcepl 1 day ago
Where you using standard optimized libraries (e.g., NumPy for numerical computation) or did you do everything in Python? This kind of increase of speed seems to indicate extremely sloppy Python programming.
[–] gf000 2 days ago
Why not go with something like graalpy first? That's much less risk in terms of "we end up slightly changing behavior"
[–] nrawe 1 day ago
It's the same level of testing for us for either Python2->3 or Go (it's a legacy code base, low automated coverage).

Conversion is now (somewhat) easier, the testing will be the slow part. For the speed improvements, which we also need for a migration from on-prem to cloud, it's a no brainer vs the other options at our disposal (like GraalPy).

[–] mring33621 2 days ago
Agree with the general workflow: prototype with an easy-to-read language then port to lower-level, faster language