113 points · by lumpa · 2y ago · 27 comments
Looks like Django is insanely faster under PyPy. Feels like a potential waste not to use PyPy on a deployed web app in most cases. I wonder how FastAPI scales with PyPy and other Python interpreters.
I don't doubt PyPy is faster than CPython, but it would be very interesting to see latest PyPy compared to latest CPython.
After a bunch of profiling, I narrowed down a bunch of our performance problems to the ORM doing a bunch of __setattr__ (or something, it was a long time ago).
We could have started rewriting everything and using .values() (or something, basically get back tuples instead of python objects) but switching to PyPy got the performance to good enough without having to sacrifice DX.
It's been a long time, so I'm a bit fuzzy on the details, but I definitely recommend PyPy for Django unless there's some reason you can't use it.
It's worked well in some cases, but the main situation where we needed it to work was with a GUI application where there was no separation between computation and the GUI elements.. I tried really hard, and got frustratingly close, but could not build wxPython that would work using pypy.
But it's super cool imo, as someone who has to write/maintain python code it's awesome to see some innovative work to make the language faster.
I much prefer Qt but this was written before I started here so it is what it is :/
The longer the test runs we end up losing data because they're looping over a dataframe that keeps growing and growing and the program just can't finish that loop in the 2 seconds that it has to run. But it's not a big enough deal for us to fix
It really does speed up loops by 5x or so.
So when you're trying to say... test 100 million+ iterations of something, pypy will run that in something like 2 minutes versus cpython can take me 15 minutes.
Honestly it's an amazing performance gain for 0 effort, and I have yet to run into a limitation with it.
If you find something like that it's worth reporting, there are less of them over time.
Apparently it took Microsoft and Facebook to actually change the minds of CPython core team, however what is coming on 3.13 is only the start.
How well does PyPy work together with frameworks like PyTorch, JAX, TensorFlow, etc? I know there has been some work to support NumPy, but I guess all these other frameworks are much more relevant nowadays.
I was recently trying to play with RPython for the first time, and having to remember all the python 2 vs python 3 differences felt strange, and very retro.
Writing RPython code, even if one is not developing or contributing to PyPy, means writing within a subset of python 2.
> RPython ("Restricted Python") is a subset of Python 2
https://www.pypy.org/posts/2022/04/how-is-pypy-tested.html
And RPython's translator specifically uses pypy, and uses python 2 syntax:
https://github.com/pypy/pypy/blob/main/rpython/bin/rpython#L...
... so getting the RPython toolchain (even if one is intending to improve the PyPy 3+ interpreters) requires setting up a pypy 2 interpreter. Hence the question in my post.