New Reference Counting: Biased & Per-Object Locks
To enable GIL-free operation, Python 3.13 introduces 'biased reference counting' and per-object locks, replacing the GIL's global protection to ensure thread safety for Python objects and memory management.
The top 3
- Biased Reference Counting: The Single-Threaded Optimization: Python 3.13's biased reference counting optimizes for common single-threaded object access by allowing the 'owning' thread to update reference counts with faster non-atomic operations, only resorting to slower atomic updates when other threads intervene. This technique was first described in a 2018 paper by Jiho Choi, Thomas Shull, and Josep Torrellas.
- GIL-Free Python's Pillars: Deferred Counts & Immortal Objects: Alongside biased reference counting, Python 3.13 introduces 'deferred reference counting' for frequently accessed objects like functions and modules, batching updates to reduce contention. Additionally, 'immortal objects' such as `None`, `True`, `False`, and small integers bypass reference counting entirely, eliminating overhead for these immutable, program-lifetime values.
- GIL-Free Performance: Single-Thread Overhead & ABI Changes: The experimental GIL-free build of Python 3.13 introduces a performance overhead of approximately 10-15% for single-threaded workloads compared to the GIL-enabled build, due to the necessary thread-safe reference counting and other per-object operations. This architectural shift also means the free-threaded build is not ABI-compatible with the standard build, requiring C extensions to be rebuilt and distributed with a separate 't' ABI tag.
Sources
Open the full topic