Why Python's GC Defaults to (700, 10, 10)

These default thresholds balance frequent collection of short-lived objects in Generation 0 with less frequent, more expensive scans for older, potentially long-lived objects in Generations 1 and 2, based on the generational hypothesis.

The top 3

  1. Generation 0's 700-Object Threshold: Why It's Key: Python's GC triggers a Generation 0 collection after 700 net new objects, optimizing for the "generational hypothesis" that most objects are short-lived and should be frequently collected to reclaim memory efficiently.
  2. How 10x Multipliers Govern Older GC Generations: The (10, 10) thresholds mean Generation 1 collects after 10 Generation 0 cycles, and Generation 2 after 10 Generation 1 cycles. This reflects the decreasing likelihood of objects being garbage as they age, thus reducing collection frequency for stable, long-lived data.
  3. Balancing Act: Default GC Thresholds vs. Custom Tuning: The (700, 10, 10) defaults aim for an optimal balance between CPU overhead and memory usage for most Python applications. However, high-performance scenarios, such as web servers, might increase `threshold0` (e.g., to 50,000) to reduce frequent GC pauses, trading memory retention for improved speed.

Sources

Open the full topic