pypy-style constant promotion to pool
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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:
- 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
PyListObjectliving in the vmdata field here https://github.com/python/cpython/blob/main/Include/internal/pycore_optimizer.h#L43 . - Introduce a new optimizer macro:
PROMOTE_TO_CONST_POOLand associated functionpromote_to_const_pool(ctx, obj)inoptimizer_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'shint(obj, promote=True)
What optimizations does this unlock?
- More constant propagation: we can now constant propagate not just immortal stuff but non-immortal things as well.
- 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! - 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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da Include/internal/pycore_optimizer.h e dal campo vmdata dell'executor, quindi esamina optimizer_bytecodes.c e optimizer_symbols.c. Il primo PR è completo quando l'executor ha un pool di costanti PyListObject, PROMOTE_TO_CONST_POOL e promote_to_const_pool esistono e i valori non immortal ricevono la propagazione delle costanti; la rimozione dei refcount è esplicitamente separata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- c
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100