python / python/cpython

pypy-style constant promotion to pool

Ouverte
#140,928 1 commentaire 5 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

interpreter-core topic-JIT type-feature
Langage dominant
Python
Étoiles
77.2k
Forks
35.9k
Métriques de merge des PR
Métriques de PR en attente

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par Include/internal/pycore_optimizer.h et le champ vmdata de l’exécuteur, puis examinez optimizer_bytecodes.c et optimizer_symbols.c. Le premier PR est terminé lorsque l’exécuteur dispose d’un pool de constantes PyListObject, que PROMOTE_TO_CONST_POOL et promote_to_const_pool existent, et que les valeurs non immortelles reçoivent une propagation de constantes ; la suppression des références est explicitement séparée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
c
Domaine
compilers
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.