python / python/cpython

JIT x Free-Threading

Offen
#141,594 2 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

interpreter-core topic-free-threading topic-JIT type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die verlinkte Diskussion in Issue 133171 und die damit verbundene Arbeit in PR 141595 zu lesen. Für den Vorschlag sind keine Dateien oder Tests benannt; für den Abschluss müsste man sich auf beide Teile — JIT und Free-Threading — einigen und sie implementieren, gefolgt von der vollständigen Testsuite einschließlich der Free-Threading-Tests.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
compilers, performance
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
20/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.