python / python/cpython

pypy-style constant promotion to pool

Abierto
#140,928 1 comentario 5 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

interpreter-core topic-JIT type-feature
Lenguaje dominante
Python
Estrellas
77.2k
Forks
36k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Proposal:

We should have a JIT constant pool and a JIT directive in the optimizer_bytecodes.c to promote certain values to constants. This would unlock significantly more future optimizations.

Steps needed:

  1. Add a constant pool to the executor object, so we can keep promoted constant alive. We already need this to unlock more constant propagation opportunities. The pool would be a PyListObject living in the vmdata field here https://github.com/python/cpython/blob/main/Include/internal/pycore_optimizer.h#L43 .
  2. Introduce a new optimizer macro: PROMOTE_TO_CONST_POOL and associated function promote_to_const_pool(ctx, obj) in optimizer_symbols.c. This macro will store any value it receives as a constant in the constant pool. This allows us to promote contants we see to the constant pool. This takes inspiration from RPython's hint(obj, promote=True)

What optimizations does this unlock?

  1. More constant propagation: we can now constant propagate not just immortal stuff but non-immortal things as well.
  2. Refcount removal. Anything in the the pool can use the cheaper _LOAD_CONST_INLINE_BORROW . Which will automatically benefit this work https://github.com/python/cpython/issues/134584 and vice versa. Ie, we automatically make it cheaper to load and store these values!
  3. On GIL/FT, we can promote method objects to the pool as well, which will allow us to perform more optimizations on them, such as LOAD_ATTR_METHOD folding.

We should also perhaps explore promoting globals to pool constants. Though that's a little risky, since we don't want to hold large objects around longer than needed.

The first PR should implement the first two steps and optimization 1. Optimization 2 should be a separate PR.

Linked PRs
  • gh-140968

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 por Include/internal/pycore_optimizer.h y el campo vmdata del executor, y después inspecciona optimizer_bytecodes.c y optimizer_symbols.c. El primer PR está completo cuando el executor tiene un pool de constantes PyListObject, existen PROMOTE_TO_CONST_POOL y promote_to_const_pool, y los valores no inmortales reciben propagación de constantes; la eliminación del recuento de referencias está explícitamente separada.

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

Evaluación

Stack tecnológico
c
Área
compilers
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.