[PYTHON] Summary of basic knowledge of PyPy Part 1

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

Python review

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.

The secret of speed

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.

What is 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.

Difference between PyPy and CPython

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)

That's all for today

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

Summary of basic knowledge of PyPy Part 1
Basic knowledge of Python
Basic usage of Pandas Summary
Basic knowledge of Linux and basic commands
Summary of basic implementation by PyTorch
2014/02/28 Summary of contents demoed at #ssmjp, part 1
Numerical summary of data
Kaggle Summary: Redhat (Part 1)
Summary of Tensorflow / Keras
Basic operation of pandas
Summary of pyenv usage
Basic usage of flask-classy
Basic usage of Jinja2
Basic operation of Pandas
Basic usage of SQLAlchemy
Python basic memorandum part 2
Basic knowledge about Linux
Python basic memo --Part 2
[Linux] Basic command summary
Summary of string operations
Summary of the basic flow of machine learning with Python
Kaggle Summary: Redhat (Part 2)
Summary of Python arguments
Summary of logrotate software logrotate
Python basic memo --Part 1
Summary of test method
Basic processing of librosa
Basic summary of data manipulation in Python Pandas-Second half: Data aggregation
Basic knowledge of DNS that can not be heard now
Basic summary of data manipulation with Python Pandas-First half: Data creation & manipulation
Python application: Pandas Part 1: Basic
Super basic usage of pytest
Summary of python file operations
Summary of Python3 list operations
2017.3.6 ~ 3.12 Summary of what we did
Basic usage of PySimple GUI
Part 1 of receiving standard input
Python Basic Grammar Memo (Part 1)
Convenient usage summary of Flask
Summary of Linux distribution types
Basic flow of anomaly detection
XPath Basics (1) -Basic Concept of XPath
One-liner basic graph of HoloViews
Basic usage of Python f-string
A brief summary of Linux
Summary of Proxy connection settings
Basics of Python × GIS (Part 1)
[Algorithm x Python] Calculation of basic statistics Part2 (mean, median, mode)
I wrote the basic operation of Pandas with Jupyter Lab (Part 1)
I wrote the basic operation of Pandas with Jupyter Lab (Part 2)