python / python/cpython

pypy-style constant promotion to pool

Aberta
#140,928 1 comentário 5 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

interpreter-core topic-JIT type-feature
Linguagem predominante
Python
Estrelas
77.2k
Forks
36k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece por Include/internal/pycore_optimizer.h e pelo campo vmdata do executor; em seguida, inspecione optimizer_bytecodes.c e optimizer_symbols.c. O primeiro PR estará completo quando o executor tiver um pool de constantes PyListObject, PROMOTE_TO_CONST_POOL e promote_to_const_pool existirem e valores não imortais receberem propagação de constantes; a remoção de refcount é explicitamente separada.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
c
Domínio
compilers
Tipo de issue
Funcionalidade
Dificuldade
5/5
Tempo estimado
Mais de uma semana
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
25/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.