Live data from Hacker News

Pyjion – A Python JIT Compiler

trypyjion.com

51–60 of 126 posts

Re: Pyjion – A Python JIT Compiler

#51
post #47

Earlier quoted context omitted.

Sounds to me like PyPy has been using Futamura projections for a decade or so.

Can you link me to some sources? I'm not familiar with PyPy but I thought it's a normal tracing JIT. In fact quick googling shows a blog post explicitly saying PyPy does NOT use PE: https://www.pypy.org/posts/2018/09/the-first-15-years-of-pyp... . Besides not every PE instance is a Futurama Projection.

PyPy is two projects.

1. RPython + the PyPy _compiler_ which is a compiler for JIT compilers (like GraalVM as I understand it)

2. An implementation of the Python language _using_ RPython to produce a JIT for Python scripts.

There are other languages _using_ RPython + PyPy compiler to produce JIT compilers for languages other than Python too.

https://doc.pypy.org/en/latest/architecture.html#layers

Re: Pyjion – A Python JIT Compiler

#52
post #47

Earlier quoted context omitted.

Sounds to me like PyPy has been using Futamura projections for a decade or so.

Can you link me to some sources? I'm not familiar with PyPy but I thought it's a normal tracing JIT. In fact quick googling shows a blog post explicitly saying PyPy does NOT use PE: https://www.pypy.org/posts/2018/09/the-first-15-years-of-pyp... . Besides not every PE instance is a Futurama Projection.

As far as I remember, PyPy uses a Python interpreter written in RPython that's being specialized with respect to the actual Python code to be executed, with the residual program implementing the semantics of that one Python program that's been fed into it.

Re: Pyjion – A Python JIT Compiler

#53
post #51

Earlier quoted context omitted.

Can you link me to some sources? I'm not familiar with PyPy but I thought it's a normal tracing JIT. In fact quick googling shows a blog post explicitly saying PyPy does NOT use PE: https://www.pypy.org/posts/2018/09/the-first-15-years-of-pyp... . Besides not every PE instance is a Futurama Projection.

PyPy is two projects. 1. RPython + the PyPy _compiler_ which is a compiler for JIT compilers (like GraalVM as I understand it) 2. An implementation of the Python language _using_ RPython to produce a JIT for Python scripts. There are other languages _using_ RPython + PyPy compiler to produce JIT compilers for languages other than Python too. https://doc.pypy.org/en/latest/architecture.html#layers

I see. This doesn't look like a Futaruma Projection to me. What PyPy does is run a python program under their own RPython based interpreter. Then it uses a tracing JIT to JIT the RPython based interpreter. There is no PE going on. No residual specialized program is created.

The first Futaruma Projection would be if PyPy would specialize the interpreter based on the python program yielding an executable.

Re: Pyjion – A Python JIT Compiler

#54

Earlier quoted context omitted.

> waiting 18 months or whatever Seems like a problem with however your system distributes software, not with Pyjion. What does it take 18 months to do?

Well for one I can't run Python 3.10 in production because I use AWS Elastic Beanstalk, which currently only supports 3.8. And my development environment is Ubuntu, which also doesn't support it out of the box. So short of scheduling two weeks to retool both my production and local development environments, which I'm not going to do because it would be a complete waste of time, there is zero benefit to me to even loo…

>Well for one I can't run Python 3.10 in production because I use AWS Elastic Beanstalk

And why wouldn't you want to try this in production in the first place?

Re: Pyjion – A Python JIT Compiler

#55

Earlier quoted context omitted.

A big difference is the Pyjion generates .NET compiler IR manually, while GraalVM generates Graal compiler IR automatically through partial evaluation of a declarative specification of an interpreter specialised to the program (the first Futamura Projection.) In my opinion that's far more powerful in terms of removing abstraction. But Pyjion also seems like a very cool project.

Damn I didn't know any of the Futamura Projections where actually implemented in practice.

About Futamura Projections (for people like me that had never heard about it): https://gist.github.com/tomykaira/3159910

Re: Pyjion – A Python JIT Compiler

#56

Earlier quoted context omitted.

A big difference is the Pyjion generates .NET compiler IR manually, while GraalVM generates Graal compiler IR automatically through partial evaluation of a declarative specification of an interpreter specialised to the program (the first Futamura Projection.) In my opinion that's far more powerful in terms of removing abstraction. But Pyjion also seems like a very cool project.

Damn I didn't know any of the Futamura Projections where actually implemented in practice.

For some reason I read this as Futurama projections.

Re: Pyjion – A Python JIT Compiler

#57

Why is there so little mention of https://cython.org/ ? It's very fast, it compiles to C code, then compiles the C code with a normal compiler.

Cython is much easier to implement than people realize. A few import statements and a few types, and then you're good to go. I urge people to give it a try. The speedups can be dramatic.

It certainly is good, but I've never found a great dev setup. It seems like you have to force a full recompile of all cython in the project any time you make a change. At least that was the stated process for the statsmodels library. And it was always a little unclear whether I was running the latest code or hadn't yet actually compiled it.

Re: Pyjion – A Python JIT Compiler

#58
post #38
post #16

The overall speed-up factor (calculated from the numbers in the Benchmarks diagram, geomean of factors) is 1.6, which is much less than the factor 4 achieved with PyPy (or the even higher factor claimed by Graal Python). CLI is not very well suited for dynamic languages; as far as I remember the results presented here correspond with Iron Python, which is to be expected based on the proposed concept. EDIT: Yes, indee…

Assuming zero compatibility problems and a simple drop in, I say 1.6 is pretty damn good from the start. Ruby' drop in YJIT barely managed ~20% speed up.

> Ruby' drop in YJIT barely managed ~20% speed up.

I don't know what they calculated, but if I use the numbers given in the table of https://speed.yjit.org/benchmarks/bench-2021-11-04-071006 I get a factor 1.9 which is much better than the reported 27%.

Re: Pyjion – A Python JIT Compiler

#59

Earlier quoted context omitted.

Well for one I can't run Python 3.10 in production because I use AWS Elastic Beanstalk, which currently only supports 3.8. And my development environment is Ubuntu, which also doesn't support it out of the box. So short of scheduling two weeks to retool both my production and local development environments, which I'm not going to do because it would be a complete waste of time, there is zero benefit to me to even loo…

Right, but those are you-problems. You use a way to get dependencies that's very slow. That's not a Pyjion problem.

> That's not a Pyjion problem.

I wasn't criticizing Pyjion, I was responding to coldtea's comment saying that people who can't run this in production would likely not be interested in trying it. I have zero issue with Pyjion, and I'm also happy with my production setup as is.

Re: Pyjion – A Python JIT Compiler

#60
post #47

Earlier quoted context omitted.

Sounds to me like PyPy has been using Futamura projections for a decade or so.

Can you link me to some sources? I'm not familiar with PyPy but I thought it's a normal tracing JIT. In fact quick googling shows a blog post explicitly saying PyPy does NOT use PE: https://www.pypy.org/posts/2018/09/the-first-15-years-of-pyp... . Besides not every PE instance is a Futurama Projection.

You're right, PyPy _used_ to base it's wizardry on PE (I don't know if it's Futurama or not, that's honestly the first time I hear of that term), but now they are using something called meta-tracing JIT, where, instead of JIT-tracing the program that your language's source describes, they JIT-trace your interepreter while it's running your language's source.

The extremly cool and awesome thing about this is that this is effectively a general purpsoe JIT, one JIT to rule all interpreted languages that could ever be written. There is nothing specific about Python in the toolchain. For _Any_ interpreted language:

- You write only your naive-but-readable interpreter in Rpython, a restricted subset of python that tries to preserve the readability but ditch the dynamic madness. (This is not python, this is an entirely different language. It just happens that every valid Rpython program is also a valid Python program. There is nothing special about Rpython here either, they could have theoretically picked any readable language to write your naive interpreter in, but they chose Rpython)

- The compilation pipeline produces two things: an exectuable image of your naive interpreter*, and a bytecode image for the general-purpose JITer.

- Normally, it's the executable image of your interpreter that runs your language's programs, but once it detects a user-program-level loop (e.g. because it has encountered a backward jump.), it invokes the supporting runtime (the general-purpose JITer) and delegates to the bytecode version of itself.

- The GP JITer starts tracing the bytecode image of your interpreter (which, remember, is itself executing the user-level program the whole time), once it detects that the user-level loop is done, it says so. Now the general-purpsoe JITer has a record of all the operations that your interpreter executed while it was running the user-level path, which is the same as {all the operations that the user-level path executed} (minus all the interpreter-specific operations, which the GP JITer also knows about because this info is contained in the bytecode)

- The GP JITer treats the execution record as any other JIT, it produces an optimised native version from it, and bingo!, you got yourself a native image of that user-level loop.

- The original interpreter, the executable, now goes back into the picture. It puts that native version of the loop in its pocket, ready for the next time it encounteres the loop.

It's so f*ing cool, that's why their logo is a snake eating itself: there's so much meta shenanigans going on. Their implementation of Python is merely the application, it's the amazing toolchain they built to build it that is the real treasure.

*: One of the steps in creating the exectuable is, I kid you not, is running the standard Cpython interpreter on your Rpython source (as it's valid python), waiting for interpreter to do it's expensive startup, then freezing the whole enviroment it produced to package it with the executable. This couldn't be done to speed up normal Python because its extremly dynamic nature messes with this.*

Post reply on HN