3 ms·
Could you tell us why CPython still doesn't have JIT? What's so hard about it (on Python)?
by tasubotadas 6y ago
Could you tell us why CPython still doesn't have JIT? What's so hard about it (on Python)?
- creata 6y agoWhy should CPython have a JIT? A good JIT is hard to write, and harder to retrofit. It usually increases startup times, attack surface, and code complexity. Besides, Python already has a handful of JIT-based implementations, and I don't see how adding the reference implementation (which out to be simple!) to that list really improves anything.
- tasubotadas 6y agoYou wrote a lot but didn't contribute to answering the question.
- creata 6y ago1. That's not a lot. 2. It's a forum, not everything has to be a direct response. 3. Either way, this was a direct response: CPython does not have a JIT because there's little reason for it to have a JIT, and many good reasons why it shouldn't. 4. If you want a JIT'd Python so badly, why not use PyPy?
- Rochus 6y agoThere is already https://www.pypy.org/ https://www.pypy.org/ which is about four times faster than CPython (which is not that much actually compared to e.g. V8, see e.g. https://benchmarksgame-team.pages.debian.net/benchmarksgame/which-programs-are-fastest.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...)
- glandium 6y agoCaveat: pypy is not _consistently_ faster than CPython. There are cases where it is slower, sometimes even by a large margin.
- Rochus 6y agoOf course. It's clearly visible e.g. on https://speed.pypy.org/ https://speed.pypy.org/ that it doesn't show equal performance on all benchmarks. The factor four corresponds to the geometric mean of all benchmarks. And as you say there are benchmarks where it even performs slower than CPython.
- CJefferson 6y agoThe biggest problem is that most nontrivial C programs use extensions written in C, and those extensions are written with fairly deep knowledge of CPython, so your JIT has to build most of the same structures as CPython anyway, in case an extension needs them.
- chrisseaton 6y agoIn the Ruby JIT I work on what we did was write a C interpreter, and run the C extensions inside the same VM as the Ruby code. That allows you to provide the illusion of using the same structures, but actually allowing you to implement them however you want for better performance.
- tasubotadas 6y agoIMO, that's a very interesting and smart approach :)
- tasubotadas 6y agoThanks. That's the answer I was looking for.
- r4victor 6y agoI'm by no means an expert on JIT compilation, but I can give a less technical answer. I think the primary reason is that most of the developers (both CPython core developers and Python developers) do not consider Python as a tool for writing perfomance critical software. So, any JIT initiative, which requires a lot of resources, doesn't get enough of them. CPython allows to write C extension modules quite easily, so if you need to write some perfomance critical piece of code , you just switch to C and call a C function from Python. Unladen Swallow was a version of CPython that added JIT support. PEP-3146 describes an unsuccessful attempt to merge it into CPython [1]. Here's a postmortem [2] Starting with version 3.6, CPython allows to set a custom frame evaluation function on the interpreter and to store JIT compiled code in a code object. This was done to support JIT in a form of a separate module and is described in PEP 523 [3]. This is very interesting topic. I should study it in detail and probably write a post. I hope I'll be able to give a more thorough answer someday. [1] https://www.python.org/dev/peps/pep-3146 https://www.python.org/dev/peps/pep-3146 [2] http://qinsb.blogspot.com/2011/03/unladen-swallow-retrospective.html http://qinsb.blogspot.com/2011/03/unladen-swallow-retrospect... [3] https://www.python.org/dev/peps/pep-0523/ https://www.python.org/dev/peps/pep-0523/
- tasubotadas 6y agoThanks. That's the answer I was looking for.
- devxpy 6y agoWhile cpython doesn't have a jit, there does exist an amazing library called numba which will run a subset of python code through a jit built using llvm and make it crazy fast (and multi-core) Intel has has a library that lets you use pandas in numba code, so it's I feel pretty confident using it in production without breaking cpython compatibility
- xioxox 6y agoCPython had one as an external module, but unfortunately it's no longer maintained as PyPy was supposed to supersede it: http://psyco.sourceforge.net/ http://psyco.sourceforge.net/ It actually worked quite well, though was pretty memory hungry.