Incorrect MRO cache entry is populated for types that do not have a version assigned
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en Objects/typeobject.c, en _PyType_LookupRefAndVersion y en el cálculo del hash de la caché alrededor de las líneas referenciadas. Sigue las rutas sin versión y con una versión recién asignada; después, verifica que las búsquedas repetidas usen la entrada de la caché indexada por la versión asignada, en lugar de dejar una entrada innecesaria. Una comprobación de regresión adecuada debería demostrar el comportamiento corregido de la caché sin cambiar los resultados de las búsquedas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- c, python
- Área
- performance
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 45/100