Atomic Overhead: 60% Slowdown without GIL

If `Py_INCREF`/`Py_DECREF` were made atomic for thread safety without the Global Interpreter Lock, CPython could face an estimated 60% performance slowdown on benchmarks, as reference counting inherently turns object reads into memory writes.

The top 3

  1. Naive Atomic Refcounting's 60% Performance Hit: Early attempts to remove Python's GIL by simply replacing `Py_INCREF` and `Py_DECREF` with atomic operations resulted in a drastic 60% average slowdown on the `pyperformance` benchmark suite, making it an unacceptable solution for single-threaded code.
  2. Biased Reference Counting: The Key Optimization: PEP 703, which makes the GIL optional, introduced biased reference counting to mitigate atomic overhead. This technique allows objects primarily accessed by a single 'owning' thread to use faster, non-atomic reference counting, while other threads use atomic operations on a separate 'shared' count.
  3. Immortal Objects & Deferred Counting Reduce Overhead to 5-10%: Beyond biased reference counting, PEP 703 also employs 'immortal objects' (like `None` and small integers that never deallocate) and 'deferred reference counting' (batching updates for frequently shared objects) to further reduce atomic overhead. These combined strategies cut the single-threaded performance cost in GIL-less Python 3.13/3.14 to just 5-10%.

Sources

Open the full topic