From the translator: in a nutshell, in December 2015, the release of Python 2.7.11 will be released, speeding up the work of the CPython interpreter to 20%. Below is a translation of the article from LWN.net , which tells about the essence and process of the changes in the code. The names, in the pronunciation of which I am not sure, are given in the original spelling. About errors and inaccuracies of the translation, please, as usual, report in private messages.Despite the fact that the development of Python 2 (specifically, the Python 2.7.x branches) is now in a state of "no new features", which normally puts an end to any major changes in advance, the development team decided to review and accept the backport patch from Python 3, bringing a noticeable performance improvement to the interpreter.
Vamsi Parasa from the team of optimization of server scripting languages ​​Intel proposed a patch (
description of the proposal with benchmarks ) that translates the
switch
block responsible for processing Python-bytecode to use a
computed goto , as it was done in Python 3. As
explained by Eli Bendersky, in such a huge
switch
block, as in the bytecode parsing unit in CPython (consisting of more than 2000 (!) lines), this gives an acceleration of about 15-20%. This happens for two reasons: the
computed goto
, unlike the
switch-case
, does not perform the boundary checks necessary for the
switch
operator according to the C99 standard, and, perhaps more importantly, the CPU can better
predict branching in such situations, which leads to reducing the number of pipeline discharges, which are by their nature an “expensive” operation.
Despite the fact that some of the CPython developers were against the introduction of this patch, because "
Performance improvement is not a bugfix ", the decision was made in favor of Intel.
')
One of the important reasons was the fact that Intel announced its readiness to further help with the support and improvement of CPython provided that the 2.7 branch is open for changes related to performance. In particular, this means that while Intel developers are engaged in “boring” parts (mainly error correction and acceleration of the 2.7 branch), volunteer developers from the opensource community will be able to spend more time on more interesting tasks:
“Do cool stuff for free, find a way to get paid for doing boring-but-necessary tasks (or leave it to those who pay for it)” - a good approach to opensource development, while trying to do everything for free is an easy way to burnout.
© Nick Coghlan
Van Rossum’s “generous lifelong dictator”
agrees with this, in particular, because the company Dropbox, for which he works, will help save “a lot of money”. According to him, in such large companies, the transition to Python 3 is rather slow, while updating to the latest actual version from the 2.7 branch is normal. Guido
disagrees with the idea of ​​“
focusing on Python 3, thereby motivating the community to migrate to it ”.
A patch that speeds up the work of the Python 2.7 interpreter is accepted (
commit ) and is scheduled for release as part of release 2.7.11, in December 2015. Despite the fact that Python 3 introduces many new features, such as
async / await ,
type naming and more , Python 2.7 is still popular (and in accordance with current plans, supported at least
until 2020 ), so this news should please a large number of Python-developers around the world.