The “Shannon Project” involved not only Guido himself, but also Eric Snow, a core CPython developer at Microsoft, and Mark Shannon, a research engineer at Semmle.
But before that, Guido didn’t think it was critical to speed up CPython, because “there are other ways to get better performance,” such as JIT-compiled PyPy, or writing extensions in C.
Why speed up?
Is Python really slow?
Not really. Development efficiency and execution speed are inherently difficult to combine.
And it has evolved to the point where Python is positioned as a glue language, primarily used to quickly build the logical control flow of a system, and then leave the performance-critical parts to C/C++ to implement.
But if you just look at the standard version of the language implementation itself …… it really doesn’t perform well.
The nature of dynamic languages dictates that Python spends a lot of time running C code (runtime) and is difficult to optimize using JIT (Just-In-Time).
In an interview with The Register, a UK-based technology news site, Shannon said in response to the question “Why are you starting to focus on CPython performance?” Shannon said.
Over the past few years, Python usage in machine learning has increased dramatically, and more and more resources have become available. This means that we can focus on performance without worrying about breaking its reliability.
And, the interpreter developed in the HotPy project, which Shannon was previously involved in, is three times faster than the current CPython interpreter for pure Python code. This demonstrates the feasibility of optimizing for CPython.
And in October of last year, Guido, who could not resist the loneliness of retirement, joined Microsoft again at
Coupled with the home squatting buff of the epidemic, the big boys with more time on their hands decided to Make Python Great Again.
The challenges before acceleration
Shannon admits that backwards compatibility was the biggest challenge in accelerating Python.
In fact, not only for Python, that incompatible update to libc in the late 90s directly led to all applications having to be reprogrammed ……
And now that Pyston is cool, the first of several factors mentioned in the official article about Dropbox abandoning the Pyston project is also.
This is a serious problem for all Python that both tries to be CPython compatible and wants to significantly improve performance.
This is because Python execution is similar to HTML rendering: more of a description of how the C library should be executed at runtime than a single-step command execution.
So the source of Python’s performance gains comes from these C extension modules. And CPython has over 400k locs, which means it’s a very large project to optimize from the bottom up.
Especially for the overly dynamic Python language, the semantics of the language have an even greater impact on optimization.
And how much of the acceleration process, like CPython tools, debuggers, configuration files, NumPy packages, and compilers like Cython, will now involve the internal and underlying behavior of CPython?
Thus Shannon states.
It is difficult to change the invisible agreement between …… and CPython users does not define very well what can and cannot be changed.
Perhaps the painful experience of migrating from Python 2.x to 3 five years ago was just a bit bitter, Guido specifically tweeted that this migration would be more peaceful.
And he pledged at the Python Summit not to break STABLE ABI compatibility; not to break LIMITED API compatibility; and not to break or slow down EXTREME cases.
“In short, maintainability of the code is the number one priority.”
Python’s Road to 5x Speed
Following faster-cpython, which has been posted on GitHub, Shannon plans to break it down into four specific phases.
is expected to be released in October of this year, adding primarily an adaptive, specialized interpreter (interpreter).
Instead of encountering runtime generated code, the interpreter will take advantage of type stability in the program, adapting to types and values during execution.
Guido has proposed to achieve at least a 2x speedup in 3.11, and to that end, he and several Python developers have put forward a proposal for enhancements, PEP 659.
This proposal indicates adding adaptive bytecode interpreters and implementing more efficient exception handling.
In addition to this, work is proposed to optimize the frame stack, change the way function calls are made, add optimizations to speed up startup time, and modify the .pyc bytecode cache file format.
This phase uses a JIT interpreter for small regions to simply and quickly compile specialized code for small regions while running code.
also compiles for extended regions at code runtime, enhancing the compiler to accomplish a 5x super speedup.
Guido says this change to Python around performance will primarily serve developers running CPU-intensive pure Python code, as well as users of built-in Python websites.
The improvements will be more limited in C code (such as NumPy and TensorFlow), I/O-bound code, multi-threaded code, and algorithmic code.
Microsoft gives back to Python
In fact, Microsoft has long been helping Python projects in a variety of ways, including releasing free Python courses in the Azure Cloud AI Services tutorials and supporting Python in Win10 and above through the VS Code Python extension.
Microsoft has also been a sponsor of the Python Software Foundation (PSF) since 2006 and is contributing $150,000 in funding this year.
There are already five core Python developer community members working at Microsoft, including the father of Python, who joined late last year, and Eric Snow, one of the three people in the Shannon program.
Guido also made a special mention of Microsoft at the summit, suggesting that Microsoft has funded a small Python team “to work on performance improvements at the interpretive level” so that he can work with Microsoft colleagues on ongoing Python development.
Of course, for the short-term goals of version 3.11, Guido still gave himself a bottom in the PowerPoint.
△”It’s always good to be optimistic and curious.”
As for the ultimate goal of four years and five times the speed, Guido said, “We have to keep our creativity high.”
/脚本：Python 3.11.0 alpha 0版本。
Posted by:CoinYuppie，Reprinted with attribution to:https://coinyuppie.com/father-of-python-make-python-2-times-faster-next-year/
Coinyuppie is an open information publishing platform, all information provided is not related to the views and positions of coinyuppie, and does not constitute any investment and financial advice. Users are expected to carefully screen and prevent risks.