Fundamentals 8 min read

What’s Coming in Python 3.12? Inside the Faster CPython Roadmap

The article outlines the major performance and architectural goals for Python 3.12, describing the Faster CPython project’s specialized opcodes, multithreading proposals, object size reductions, memory‑management improvements, and API stability efforts that aim to boost speed and maintainability.

21CTO
21CTO
21CTO
What’s Coming in Python 3.12? Inside the Faster CPython Roadmap

Python 3.11.0 was released on October 24 2022, delivering a 10‑60% speed boost over 3.10 thanks to the Faster CPython ("Shannon") project.

Details about the "Shannon" plan can be found in Guido van Rossum’s talk and a related podcast interview.

Python 3.11 marks an exciting start for interpreter speedups, and the next release, 3.12, promises further advances.

Author: Mark Shannon Translator: 豌豆花下猫 @ Python猫 Original English source: https://github.com/faster-cpython/ideas/wiki/Python-3.12-Goals

This content may change; refer to the actual release for final details.

The article summarizes the main Faster CPython initiatives planned for Python 3.12.

Tracking Optimizer

Python 3.11 improves speed by replacing selected bytecodes with faster, context‑specific specialized opcodes. The next major improvement will optimize sequences of opcodes.

Many high‑level opcodes will be replaced by lower‑level ones, such as those handling version checks and reference‑counting, making them easier to optimize and allowing redundant reference‑count operations to be removed.

These lower‑level opcodes also provide a set of instructions suitable for generating machine code, useful for CPython and third‑party JIT projects.

The interpreter loop will be generated from a declarative description, reducing bugs related to synchronizing the loop with related functions and enabling larger experimental changes.

Multithreaded Parallelism

Current Python processes are limited by the Global Interpreter Lock (GIL), preventing true multithreaded parallelism.

PEP‑684: https://peps.python.org/pep-0684 PEP‑554: https://peps.python.org/pep-0554

PEP‑684 proposes making all global state thread‑safe and moving it into each sub‑interpreter’s own lock.

PEP‑554 introduces a C‑API feature for creating sub‑interpreters, enabling true multithreaded parallelism.

Python猫 note: PEP‑554 was proposed in 2017 for Python 3.8‑3.9 but was not implemented. In 2019 I translated an article titled “Has the Python GIL been slain?”

More Specialization

We have analyzed which bytecodes will benefit most from specialization and plan to complete the remaining high‑impact improvements in 3.12.

https://github.com/faster-cpython/ideas/issues/74

Smaller Object Structures

There are many opportunities to reduce the size of Python object structures. Because these objects are frequently used, smaller structures improve overall memory usage and cache consistency. We plan to implement the most promising ideas in 3.12.

Some trade‑offs between backward compatibility and performance may require a new PEP to reach consensus.

Reducing Memory‑Management Overhead

We will not only shrink object sizes but also make their layout more regular.

This will optimize memory allocation and deallocation and speed up object traversal during garbage collection and reallocation.

API Stability

Beyond the projects above, the development team will improve the overall quality of the CPython codebase:

Reduce coupling between compilation stages to make the compiler easier to maintain and test.

Actively monitor and improve CPython test‑suite code coverage at the C level.

Enhance Python performance benchmarks with more representative real‑world workloads.

Assist with CPython issues and PRs, especially those related to performance.

Add benchmark machines for standard tests, including macOS and Windows results.

Continue collaborating with major projects that heavily use the Python core to help them adapt to interpreter changes.

Note: Images in the article were added by the translator.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performanceMemory ManagementPythoninterpreterCPythonPEPSpecialization
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.