Add a `PyThreadState *` parameter (almost) everywhere
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
This is part feature request, part performance issue and part a general appeal for assistance.
We should add a new variant taking a PyThreadState * parameter for most C API and internal functions.
There are two motivations for this, performance and a future, consistent C API.
Performance
The PyThreadState struct is ubiquitous in the VM, it controls stack usage, holds the freelists, holds the current exception, etc, etc.
Consequently many C functions, both API and internal, take a PyThreadState *tstate parameter.
However, for historical reasons, many C functions, both API and internal, do not such a parameter.
This leads to some fairly easy to fix inefficiencies, where spam() and eggs() take a thread state, but ham() does not, then spam() calls ham() which calls eggs(), forcing ham() to load the thread state from thread local storage, in order to pass it to eggs().
Adding a PyThreadState *tstate to ham() avoids need to access thread local storage.
Consistent, portable, future looking C API
In order to support things like tagged integers, we are going to need to a new C API.
It is out of scope to discuss what such an API would look like, but all realistic proposal so far take a "context" parameter to all, or almost all, API functions. Using a PyThreadState * parameter everywhere would make a mechanical transformation from old to new API much simpler.
Unfortunately the C API is large and cannot be changed, so we will need many new functions, like ham_tstate() which replicates ham() but with a thread state parameter.
This work is largely mechanical, and can be done by inexperienced contributors. Hence the appeal for assistance.
Linked PRs
- gh-151453
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Das Issue nennt keine spezifischen Dateien, Tests oder Einstiegspunkte; beginne mit der Prüfung des verknüpften PR gh-151453 sowie der C API und der davon abgedeckten internen Funktionen. Als abgeschlossen gilt die Arbeit, wenn der vereinbarte Umfang entsprechende PyThreadState-aware-Varianten hat und die ausgewählte Arbeit vollständig erledigt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- c, python
- Bereich
- api, backend
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 20/100