Hacker News new | ask | show | jobs
by RussianCow 3540 days ago
PyPy uses a JIT (just-in-time) compiler, as opposed to the static interpreter of CPython (the default/canonical implementation of Python from python.org). What this means is that the PyPy interpreter uses runtime information about your program to compile your Python code into very efficient machine code on the fly. Because this compilation is done at runtime, PyPy has lots of data about things like variable types, how often each function gets called, etc, and it can use that data to generate really fast code in many cases.

PyPy is a completely different implementation of Python, so it's impossible to simply contribute improvements from it to CPython. To answer the question I think you're asking, though, the main reason we can't just have PyPy replace CPython as the default implementation isn't strictly technical: The Python community (Guido in particular) has decided to keep the reference implementation (CPython) as simple and consistent as possible, so that it's easy to contribute to and doesn't have any surprising behavior. PyPy, by comparison, is an incredibly complex piece of software. Even if you ignore the fact that it would make contributions harder, its performance is, in many scenarios, actually significantly worse than CPython's, because its optimizations rely on specific patterns within your code. I think it's mostly a good thing that PyPy is its own project and not the default implementation of Python, because it allows Python (the language) to grow much faster than it would otherwise.

I hope that answers your question. I apologize to anyone who knows more about the details than I do if I over-simplified things. :)

1 comments

The complexity of the JIT isn't in pypy's implementation of python. This is probably the most important part of the pypy project: it's a python implementation written in a simple subset of python plus some standard hints, and an independent piece that generates a JIT for things written in that subset.