Skip to content

gh-144960: Clarify GC threshold1 formula in set_threshold docs#145285

Open
Anandesh-Sharma wants to merge 1 commit intopython:mainfrom
Anandesh-Sharma:fix-gc-threshold-docs
Open

gh-144960: Clarify GC threshold1 formula in set_threshold docs#145285
Anandesh-Sharma wants to merge 1 commit intopython:mainfrom
Anandesh-Sharma:fix-gc-threshold-docs

Conversation

@Anandesh-Sharma
Copy link

@Anandesh-Sharma Anandesh-Sharma commented Feb 26, 2026

Summary

  • Clarifies the gc.set_threshold() documentation for the threshold1 parameter
  • Shows the actual formula 1/(10 * threshold1) instead of just stating "inversely proportional"
  • Resolves the confusion noted in the usage of threshold1 for the GC is not correctly explained #144960 where "inversely proportional to threshold1" with a default of 10 would naively imply 10% (1/10), not the actual 1%
  • The constant factor of 10 comes from the internal SCAN_RATE_DIVISOR in Python/gc.c

Fixes #144960

Test plan

  • Documentation renders correctly with make -C Doc html
  • Formula matches the implementation in Python/gc.c (SCAN_RATE_DIVISOR = 10)

📚 Documentation preview 📚: https://cpython-previews--145285.org.readthedocs.build/

The documentation stated that the fraction of the old generation scanned
is "inversely proportional to threshold1" and that the default value of
10 results in 1% being scanned. However, this was confusing because a
naive interpretation of "inversely proportional" (1/threshold1 = 1/10 =
10%) does not match the stated 1%.

Clarify by showing the actual formula: 1/(10 * threshold1), which
accounts for the internal SCAN_RATE_DIVISOR constant of 10.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@python-cla-bot
Copy link

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

the usage of threshold1 for the GC is not correctly explained

1 participant