Question about this JIT implementation.
As far as I could tell from reading PEP-744, the JIT will do something to compile Python byte code into machine code before it is executed.
What I don’t understand is why does that only give a 5 % increase in performance. (I have seen this figure quoted in more than one source.)
- Is the fact that a Python bytecode layer exists an inherent limitation?
- If so, why not get rid of the bytecode layer altogether, or at least aim to do so at some point in the future?
I am by no means an expert in compiler implementation, but Python is known for being an anomaly in the world of software engineering because it is so exceptionally slow.
Compare it to Node.js, for example. Node has pretty good performance despite the fact that it executes JavaScript. IIRC Node executes all code using 4 threads, two of which do IO, one of which does the actual execution of the JavaScript once it has been through the Node JIT stage, the other thread I do not recall exactly what it does.
You can compare the performance of Node to Python by restricting yourself to code which is CPU intensive, and does not do much IO. (The sensible thing you would do by default anyway.)
Unless I have misunderstood, you typically expect to get much better performance out of a Node.js webserver than a Python one.
A commonly quoted figure is that Python is about 20x slower than most other languages. There is some variance between all languages, but Python stands out as being the anomaly.
Why is this?
- Is it because Python generates a bytecode which perhaps limits performance in a way that Java (also compiles to bytecode) does not?
- It is an inherent limitation of Python’s memory model (object model). Again I am no expert, but the object model requires a lot of indirection (following pointers) to figure out how to execute a function on an object. On the other hand, I was recently told that CPUs have lots of hardware optimizations to help with virtual function calls and following pointer indirection.
- Is the JIT just new technology? Should we anticipate seeing much greater improvements in runtime performance in the future?
- What is the theoretical limit of the JIT? Could we anticipate numbers like a 500% performance gain at some point in the future? (Unless my figures are off, a 5x performance improvement would put Python on par with some of the other languages, maybe Java, for example.)
PS: I’m aware that for the context of performing big data operations with Numpy or DataFrames, the fact that all the code is implemented at the C level changes the situation somewhat. But this limits Python to a small subset of problems. I don’t know how you would implement a webserver using a Pandas DataFrame, for example.
Basically -
- The 5% performance gain figure seems a bit too small
- and more generally, I’m interested to know what future performance gains might be anticipated or could be achievable
Thanks