python Python PEPs ·

PEP 848 Proposes Generational Incremental Garbage Collection for CPython

infraengineer
announcement

PEP 848 introduces a proposal for a new generational and incremental cyclic garbage collector in CPython, targeting Python 3.16. This collector aims to significantly reduce GC pause times, potentially by up to 100-fold in large-heap programs, and improve overall performance by 3-5% on benchmarks. It achieves this by focusing collections on parts of the heap where garbage is more likely to accumulate, addressing inefficiencies of the current collector. The existing generational collector will remain an available option for developers.

  • →New Generational Incremental Garbage Collector Proposed
  • →Significant Performance and Pause Time Reductions
  • →Motivation and Improvements Over Current Collector
  • →Design Principles and Specification
Notes (4) ›
  • New Generational Incremental Garbage Collector Proposed

    PEP 848 outlines a new cyclic garbage collector for CPython that is both generational and incremental. It will alternate between young and incremental old collections, focusing on specific parts of the heap where garbage is most concentrated.

  • Significant Performance and Pause Time Reductions

    The proposed collector aims to reduce GC pause times by up to a factor of 100 in programs with large heaps, alongside a 3-5% overall performance improvement on the pyperformance benchmark suite. Peak memory use is expected to decrease for larger heaps but may increase for smaller, shorter-lived programs.

  • Motivation and Improvements Over Current Collector

    The current generational collector is inefficient due to scanning live objects, examining objects too frequently, and performing full heap scans, leading to long pause times. The new design targets older objects and performs incremental scans, increasing effectiveness and reducing pauses.

  • Design Principles and Specification

    The collector design prioritizes total program run time, maximum GC pause time, and peak memory use. It divides the heap into three generations (Nursery, Aging, Old) and further splits them into spaces, with a specific alternating algorithm for collecting increments of the old generation and the oldest young generation space. The existing non-incremental collector will remain an option.

Read the original announcement →

https://peps.python.org/pep-0848/

Related releases