Incorrect MRO cache entry is populated for types that do not have a version assigned
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:
_PyType_LookupRefAndVersion will populate the incorrect cache entry if it is called with a type that does not have a version tag (tp_version_tag is 0). I think this only impacts performance, not correctness. The next call to _PyType_LookupRefAndVersion for the same (type, name) pair will miss the cache, but will populate the correct entry, so any subsequent calls will hit the cache. Additionally, this may create some amount of unnecessary thrash on the cache.
The root of the issue is that the version tag is an input to the hash that is used to determine the cache entry and we do not recompute the hash, and the associated cache entry, after assigning a version.
_PyType_LookupRefAndVersion first computes the cache entry:
If the cache entry doesn't match, and a type version was assigned successfully, it populates the same entry:
The next call for the same (type, name) pair, will find a different entry, because the type version is used to compute the hash that indexes into the cache:
It looks like the change to use the same entry was introduced in gh-113930. cc @DinoV
CPython versions tested on:
3.13, 3.14
Operating systems tested on:
Linux
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
Inizia in Objects/typeobject.c, in _PyType_LookupRefAndVersion e nel calcolo dell’hash della cache attorno alle righe indicate. Segui i percorsi senza versione e con una versione appena assegnata; quindi verifica che le ricerche ripetute usino la voce della cache indicizzata dalla versione assegnata, invece di lasciare una voce non necessaria. Un controllo di regressione adeguato dovrebbe dimostrare il comportamento corretto della cache senza modificare i risultati delle ricerche.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- c, python
- Ambito
- performance
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100