GC: Implementation does not match behavior documented on `gc.set_threshold`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug report
Bug description:
The documentation of gc.set_threshold states:
In order to decide when to run, the collector keeps track of the number object allocations and deallocations since the last collection. When the number of allocations minus the number of deallocations exceeds threshold0, collection starts
This doesn't seem to be accurate. Looking at the implementation, it appears that young.count is being used to track number of allocations minus the number of deallocations. However it doesn't actually track this due to the if (gcstate->young.count > 0) check here: https://github.com/python/cpython/blob/3.13/Python/gc.c#L2119.
As a concrete example, suppose threshold0=500. Suppose the GC runs and young.count is reset to 0, then 500 deallocations happen (by object ref counts dropping to 0), then 500 allocations happen. According to the documentation the GC would not run in this case, because the difference between allocations and deallocations is 0. However the actual tracked number in young.count will be 500, and GC will trigger.
I'm unsure which is the expected behavior; the documented one or the implemented one, but it does appear that the two do not currently agree.
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Linked PRs
- gh-156877
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Iniziate dal comportamento documentato di gc.set_threshold e dalla gestione di young.count in Python/gc.c intorno alla riga 2119. Confrontate lo scenario di allocazione e deallocazione riportato con l’implementazione, quindi esaminate il PR collegato gh-156877; il lavoro è completo quando implementazione e documentazione concordano sul comportamento previsto della soglia.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100