News for hackers. Stuff that matters.
Re:How the CPython compiler works by r4victor on Wednesday September 23, 2020 @07:22AM (#24565626)
Hi! This is the second part of my new Python behind the scenes series that covers the compilation of a Python program. I'd be glad to hear your thoughts on this part and the series in general.
Re:How the CPython compiler works by tasubotadas on Thursday September 24, 2020 @06:05AM (#24577040)
Could you tell us why CPython still doesn't have JIT? What's so hard about it (on Python)?
Re:How the CPython compiler works by r4victor on Thursday September 24, 2020 @08:45AM (#24578062)
I'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

[2] http://qinsb.blogspot.com/2011/03/unladen-swallow-retrospect...

[3] https://www.python.org/dev/peps/pep-0523/

Re:How the CPython compiler works by tasubotadas on Thursday September 24, 2020 @11:36AM (#24579616)
Thanks. That's the answer I was looking for.
Re:How the CPython compiler works by CJefferson on Thursday September 24, 2020 @08:31AM (#24577955)
The 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.
Re:How the CPython compiler works by chrisseaton on Thursday September 24, 2020 @10:20AM (#24578843)
In 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.
Re:How the CPython compiler works by tasubotadas on Thursday September 24, 2020 @11:38AM (#24579643)
IMO, that's a very interesting and smart approach :)
Re:How the CPython compiler works by tasubotadas on Thursday September 24, 2020 @11:37AM (#24579621)
Thanks. That's the answer I was looking for.
Re:How the CPython compiler works by Rochus on Thursday September 24, 2020 @07:51AM (#24577673)
There is already 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/...)
Re:How the CPython compiler works by glandium on Thursday September 24, 2020 @06:47PM (#24584583)
Caveat: pypy is not _consistently_ faster than CPython. There are cases where it is slower, sometimes even by a large margin.
Re:How the CPython compiler works by Rochus on Thursday September 24, 2020 @06:55PM (#24584639)
Of course. It's clearly visible e.g. on 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.
Re:How the CPython compiler works by devxpy on Thursday September 24, 2020 @09:42AM (#24578521)
While 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

Re:How the CPython compiler works by creata on Thursday September 24, 2020 @06:17AM (#24577106)
Why 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.

Re:How the CPython compiler works by tasubotadas on Thursday September 24, 2020 @07:34AM (#24577553)
You wrote a lot but didn't contribute to answering the question.
Re:How the CPython compiler works by creata on Thursday September 24, 2020 @07:40AM (#24577588)
1. 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?

Re:How the CPython compiler works by xioxox on Thursday September 24, 2020 @09:49AM (#24578572)
CPython had one as an external module, but unfortunately it's no longer maintained as PyPy was supposed to supersede it: http://psyco.sourceforge.net/

It actually worked quite well, though was pretty memory hungry.

Re:How the CPython compiler works by Ennea on Thursday September 24, 2020 @05:31AM (#24576860)
This could be an interesting read, but so far I've only had time to skim it. What I did notice, however, is that some of your images are too wide and get cut off :)
Re:How the CPython compiler works by r4victor on Thursday September 24, 2020 @06:46AM (#24577246)
I know the site is not well adapted for mobiles. I currently use default Pelican theme, which is not responsive, and have plans to change it. Nevertheless, I have no problems with displaying images on any device (desktop/ipad/iphone), so could you elaborate on this? What device do you use? You can email me: [email protected]
Re:How the CPython compiler works by Ennea on Thursday September 24, 2020 @07:09AM (#24577388)
Desktop, actually. Full HD. The width of the content is only 800px, but some of your images (like diagram2.png) is 1044px wide. And instead of the image being scaled, it is just being cut off.

Edit: Oh yea, there we go. You're using CSS zoom[0], which is non-standard.

[0] https://developer.mozilla.org/en-US/docs/Web/CSS/zoom

Re:How the CPython compiler works by lordgrenville on Thursday September 24, 2020 @07:18AM (#24577448)
Same for me. Firefox desktop on macOS https://pasteboard.co/Jsysfju.png
Re:How the CPython compiler works by r4victor on Thursday September 24, 2020 @07:46AM (#24577634)
Thanks for reporting! Fixed this. I used a non-standard `zoom` attribute, which works in Chrome and Safari. It's a good habit to check how the website looks in all major browsers.