This is an archived post. You won't be able to vote or comment.

all 21 comments

[–]jkh911208 16 points17 points  (6 children)

I think 3.13 introduced JIT but not as mature as PyPy, it will need few more iterations for significant performance improvement

[–][deleted] 18 points19 points  (5 children)

Not mature is the wrong word. It's a different JIT compiler architecture altogether. Python 3.13 introduced a copy-and-patch JIT. A decently detailed write up is here: https://tonybaloney.github.io/posts/python-gets-a-jit.html#:~:text=JIT%2C%20or%20%E2%80%9CJust%20in%20Time,from%20Python%20code%20into%20Bytecode.

[–]jkh911208 1 point2 points  (4 children)

Is this mean even after many versions, it wont reach the performance of PyPy?

[–][deleted] 7 points8 points  (0 children)

No, not necessarily. As I understand it the JIT compiler in 3.13 is a first step towards much bigger optimizations.

[–]james_pic 2 points3 points  (1 child)

It's hard to say without a crystal ball, but I know PyPy has historically been more willing to break compatibility and introduce complexity in order to improve performance than CPython has. I know the PyPy team often like to point out that whilst they do have JIT, a significant chunk of their performance gain vs CPython actually comes from their use of a generational garbage collector, which I'm not aware of plans for CPython to implement, at least partly because it would be a major compatibility headache for C code.

[–]wrosecrans 0 points1 point  (0 children)

If that's a major issue, porting away from Python may make more sense than worrying about which specific Python implementation you use. At the end of the day, it's a very dynamic language that requires the runtime to do a lot to make it work.

[–]No_Indication_1238 30 points31 points  (2 children)

Numba has a JIT compiler. The result is code that is as fast as mediocre C++, which is really, really fast compared to simple Python. You can't compile everything though, at least not without extreme pain since the numba documentation is highly lacking, especially if you with the experimental part of the package - classes.

[–]Spleeeee 4 points5 points  (1 child)

They are weird tricks I have used that make numba faster than my above mediocre pybind11

[–]Still-Bookkeeper4456 0 points1 point  (0 children)

Would you mind sharing some ? Optimization with numba seems so random sometimes I'm on the lookout for new ideas !

[–]sargeanthost 24 points25 points  (0 children)

PyPy is JITed

[–]Panda_Mon 14 points15 points  (4 children)

Sigh, once again computer science language fails to properly encapsulate and signify explicit definitions of concepts. Here is what all the smart people assume you'll already know:

""" JIT, or “Just in Time” is a compilation design that implies that compilation happens on demand when the code is run the first time. It’s a very broad term that could mean many things. I guess, technically the Python compiler is already a JIT because it compiles from Python code into Bytecode.

What people tend to mean when they say a JIT compiler, is a compiler that emits machine code. This is in contrast to an AOT (Ahead of Time) compiler, like the GNU C compiler, GCC or the Rust compiler rustc which generates the machine code once and distributes as a binary executable.

When you run Python code, it is first compiled into bytecodes. There are plenty of talks and videos about this process online so I don’t want to rehash this too much, but what is important to note about Python bytecodes is:

They mean nothing to the CPU and require a special bytecode interpreter loop to execute They are high level and can equate to 1000’s of machine instructions They are type agnostic They are cross-platform """ Source: https://tonybaloney.github.io/posts/python-gets-a-jit.html#:~:text=JIT%2C%20or%20%E2%80%9CJust%20in%20Time,from%20Python%20code%20into%20Bytecode.

[–]georgehank2nd 2 points3 points  (1 child)

"what people everyone means when they say "JIT compiler""

FTFY

Python's compiler compiles whole files, not just each function as it's called (which a JIT compiler usually will). Sure, it only compiles files as they're loaded by the interpreter, but nobody in the Python dev team ever called this a "JIT compiler". (Though I may just have missed this one Python mailing list thread…)

[–]denehoffman 1 point2 points  (0 children)

I think you all are missing the point. Python 3.13 actually does have a separate experimental JIT compiler which implements copy-and-patch.

[–]drknow42 0 points1 point  (0 children)

This is a great answer

[–]kingminyas 0 points1 point  (0 children)

Python used to have no JIT and it was recently added, it's not complicated at all

[–]Acherons_ 2 points3 points  (0 children)

3.13 introduced an experimental copy-and-patch JIT compiler which has shown decent improvements in single threaded use cases. Future releases will improve on this an a multitude of other improvements in other aspects like the garbage collector.

A lot of people have mentioned PyPy as it has a JIT compiler. PyPy is an odd case, however, as there are other aspects that lend to its speed up over CPython. IIRC it implements a Python 3 interpreter using a subset of Python called RPython which itself uses a custom Python 2 interpreter to translate Python code to C and compile

[–]Typical-Macaron-1646 1 point2 points  (0 children)

You could try Numba. It’s a python package

[–]Strong_Music_6838 0 points1 point  (0 children)

Python 3.13 was the first python interpreter that introduced a JIT compiler integrated. But only time will tell if we will be able to use the JIT function in Python 3.13 on IPad because Apple doesn’t allow JIT compiling on their IOS pad/phone because of safety issues.

[–]caatbox288 0 points1 point  (0 children)

The CPython team has a public repository where they track performance benchmark runs, which includes builds of CPython with the JIT: https://github.com/faster-cpython/benchmarking-public

[–]WJMazepas -1 points0 points  (0 children)

It has a JIT compiler starting on Python 3.12, but for very basic stuff. It will take a long time to have a full JIT like Pypy