Home > Article > Backend Development > The goal of Python 3.12: more efficient performance!
According to the release plan, Python 3.11.0 will be released on October 24, 2022.
According to testing, 3.11 will have a 10-60% performance improvement compared to 3.10. This achievement is mainly attributed to the "Faster CPython" project, also known as the "Shannon Project".
The 3.11 version is an exciting start for Python’s speedup. More action is coming in 3.12 next.
The following article is translated from "Python 3.12 Goals" by "Shannon Project", let's take a look first!
The content of this article may be changed, the actual version shall prevail!
This article is a summary of the main content that Faster CPython plans to implement in 3.12.
The main way to improve speed in Python 3.11 is to replace individual opcodes with faster context-sensitive opcodes (adaptive specialization opcodes), next A big improvement would be to optimize the running of multiple opcodes.
To do this, many of the existing high-level opcodes will be replaced with low-level opcodes, such as those used to check version numbers and reference counts. These simpler opcodes are easier to optimize, for example, redundant reference counting operations can be removed.
These lower-level opcodes also give us a set of instructions suitable for generating machine code (in both CPython and third-party JIT projects).
To do this, an interpreter loop will be generated based on the declarative description.
This can reduce some of the bugs caused by keeping the interpreter loop synchronized with certain related functions (mark_stacks, stack_effect, etc.), and also allows us to experiment with larger changes to the interpreter loop.
Python currently has a global interpreter lock (GIL) per process, which hinders multi-threaded parallelism.
PEP-684 proposed a solution to ensure that all global state is thread-safe and moved to the global interpreter lock of each sub-interpreter use.
PEP-554 proposes a solution for Python to create a sub-interpreter (currently only a C API feature), thereby achieving true Multi-threaded parallelism.
We analyzed which bytecodes will benefit the most from specialization, and plan to 3.12 Complete the remaining high-yield improvements.
https://www.php.cn/link/7392ea4ca76ad2fb4c9c3b6a5c6e31e3
There are many opportunities to reduce the size of Python object structures. Since they are used frequently, this not only benefits overall memory usage, but also cache consistency. We plan to implement some of the most promising ideas in 3.12.
There are some trade-offs between backward compatibility and performance, and a PEP may need to be proposed to establish consensus.
We will not only reduce the size of objects, but also make their layout more regular.
This not only optimizes memory allocation and deallocation, but also speeds up object traversal during GC and reallocation.
In addition to the aforementioned projects, the development team will also improve the overall quality of the CPython codebase:
The above is the detailed content of The goal of Python 3.12: more efficient performance!. For more information, please follow other related articles on the PHP Chinese website!