PyPy is said to be faster than Python. What is it really like?
Even with the help of Google teacher, in Japanese, "It's like this!" Only Wikipedia teacher can find the explanation.
If it is an English site, there are relatively many articles on blogs etc. so do your best I tried to summarize a little.
Note. Extraction and summary from various documents, but translation and interpretation It may be wrong. If you point out, we will correct and add it.
Each reference site etc. https://ja.wikipedia.org/wiki/PyPy http://pypy.org/index.html http://shomah4a.net/pypy-tutorial/ http://stups.hhu.de/mediawiki/images/f/f5/Tracing_JITs11_tracing_the_meta_level.pdf
Before PyPy, first about Python. Widely used so-called Python refers to CPython implemented in C language. (There are also Jython running on JavaVM and IronPython running on .Net) And PyPy is a (self-hosted) Python reimplemented in Python. So if PyPy is Python reimplemented in CPython, then it's 70 points (appropriate score).
RPython By the way, CPython has a subset called RPython.
A subset is a part of a system or programming language As a familiar example, VBA is a subset of Visual Basic 6.
In addition, the "R" in RPython is Restricted. In other words, RPython was reimplemented in CPython with restrictions and restrictions on CPython. It's a subset of Python (difficult ...).
And PyPy is implemented in this RPython. In conclusion, what is PyPy? ** Python implemented in RPython, a subset of CPython implemented in C ** It means that.
I'll talk about why I made RPython a little later.
One of PyPy's selling points is "faster execution than CPython". Why is it faster even though the original is the same Python? It's by JIT.
"Just In Time Compiler", just-in-time compilation. By compiling and converting to machine language in function units and module units Increases execution speed. (Interpreter is executed line by line)
By the way, RPython implements type inference, It seems that it contributes to optimization at compile time.
http://shomah4a.net/pypy-tutorial/ Has a tutorial explanation for converting to machine language, so if you are interested, please do.
(Further supplement) The PyPy required for the tutorial is Mercurial cloned from the official BitBucket. https://bitbucket.org/pypy/pypy As explained on the PyPy official download page, Please note that it is located at the bottom, apart from the binaries for the execution environment at the top. Also, if you only use RPython, you can drop it with pip normally. There is surprisingly little information on how to introduce this area.
PyPy was further implemented from RPython for compatibility with CPython code, Still, there are differences. Below are some of them.
--Cannot use Python library written in C language --The garbage collection method is different
The reason why you can't use the C language library is from RPython. However, there is also a PyPy version of NumPy, so it seems that it is being followed to some extent.
Garbage collection claims that it is not based on reference counting, Then what are you using? It's not clear ... I think it's a mark-and-sweep (guess). If you look at the source, it's one shot (difficult to read)
I tried to find out from the fact that I do not know PyPy in the first place, Not very well organized. I will continue to investigate, so the story I will put it together again as soon as it accumulates.
Recommended Posts