python / python/cpython

Avoid refcounting on code objects during frame creation/destruction

Abierto
#152,666 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

3.16 interpreter-core performance
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

The __code__ attribute of function objects is assignable.
As a consequence, frames must hold a strong reference to the code object in case the reference held by the function is lost.

Ideally, the __code__ attribute would be read-only, but to fix that would be a multi-year deprecation effort.

Until that happens, if ever, we can replace the strong reference with a borrowed reference to the code object as long as code object is guaranteed to outlive the frame.
Since the function will outlive the frame, if the function object keeps references to its prior __code__ attributes
when __code__ is assigned, then the code object will always outlive the frame.

This will need an extra field in each function, but the cost of one assignment to NULL during function creation, is much less than the cost of an incref and a decref on every call to that function.

The only downside is that in some obscure cases the lifetime of a few code objects will be extended.
Since the free-threading build makes all code objects immortal, this could actually be a big saving for the free-threading build.

Linked PRs
  • gh-152955

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza revisando el PR vinculado gh-152955 y, a continuación, sigue el rastro de los objetos de función, los frames y los objetos de código en torno al atributo code y a la creación y destrucción de frames. Se considera terminado cuando se demuestre que los objetos de código sobreviven a sus frames evitando operaciones de conteo de referencias en cada llamada, y las pruebas pertinentes de CPython siguen pasando.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
backend
Tipo de issue
Refactorización
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.