python / python/cpython

JIT x Free-Threading

Aperta
#141,594 2 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

interpreter-core topic-free-threading topic-JIT type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Feature or enhancement

Proposal:

This provides an alternative design to https://github.com/python/cpython/issues/133171. I have a branch where all tests (including FT) pass.

Part 1:
For the first and simplest part, we could add a watcher/callback to thread creation. When multiple threads are created, we simply invalidate the executor as _CHECK_VALIDITY fails.

This means single threaded code gets all the benefits of JIT in the future, while multi-threaded code will lose all the benefits. However, both can coexist at the same time in the same build. We will finally get JIT + FT in a limited form. Pending part 2.

Part 2:
If we detect multiple threads are running, we turn off the non-thread safe optimizations, and redo the trace with those optimizations off. If we detect only a single thread, we follow part 1 and run till we get invalidated. This allows single threaded code to run faster, while multi-threaded code will run a little slower. Note that all optimizations I've proposed for the JIT in the past 6 months and in the future are FT safe (in theory. whether they are implemented in practice is different).

Together, part 1 and part 2 get the best of both worlds: for single-threaded code, we get max performance, even recovering some of the perf single-threaded perf lost from FT. In part 2, we get max compatibility with multiple threads.

We need both parts to get the max perf out of the JIT on FT.

Follow-up after this:

  • Lock/unlock removal in FT code.
Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

https://github.com/python/cpython/issues/133171

Linked PRs
  • gh-141595

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia leggendo la discussione collegata nell’issue 133171 e il lavoro correlato nella PR 141595. La proposta non indica file o test; per completarla sarebbe necessario concordare e implementare entrambe le parti, JIT e free-threading, seguite dall’esecuzione dell’intera suite di test, inclusi i test di free-threading.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
compilers, performance
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
20/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.