python / python/cpython

GC: Implementation does not match behavior documented on `gc.set_threshold`

Ouverte
#122,862 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

docs
Langage dominant
Python
Étoiles
77.2k
Forks
35.9k
Métriques de merge des PR
Métriques de PR en attente

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par le comportement documenté de gc.set_threshold et la gestion de young.count dans Python/gc.c autour de la ligne 2119. Comparez le scénario d’allocation et de désallocation signalé avec l’implémentation, puis examinez le PR associé gh-156877 ; le travail est terminé lorsque l’implémentation et la documentation concordent sur le comportement attendu du seuil.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
backend
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.