Incorrect MRO cache entry is populated for types that do not have a version assigned
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in Objects/typeobject.c bei _PyType_LookupRefAndVersion und der Cache-Hash-Berechnung um die referenzierten Zeilen herum. Verfolge die Pfade ohne Version und mit neu zugewiesener Version. Überprüfe anschließend, dass wiederholte Lookups den Cache-Eintrag verwenden, der über die zugewiesene Version indiziert ist, anstatt einen unnötigen Eintrag zurückzulassen. Eine geeignete Regression-Prüfung sollte das korrigierte Cache-Verhalten demonstrieren, ohne die Lookup-Ergebnisse zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- c, python
- Bereich
- performance
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100