CALL_FUNCTION_EX argument passing routine can be improved for vectorcalls

Offen
#95,757 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Refactoring
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
compilers

Rechercherichtung

Verfolge den Argumentfluss durch do_call_core, _PyVectorcall_Call, _PyStack_UnpackDict, _PyEval_Vector, _PyEvalFramePushAndInit und initialize_locals. Verstehe zunächst, wie CALL_FUNCTION_EX vectorcall-Python-Funktionen erreicht und wie der Besitz an jeder Grenze gehandhabt wird. Die Arbeit ist abgeschlossen, wenn der Pfad das intermediäre C-Array und die Neuerstellung von tuple/dict vermeidet und dabei den korrekten Besitz der Argumente und das korrekte Verhalten beibehält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

interpreter-core performance type-feature

While working on https://github.com/python/cpython/issues/95126, I noticed that CALL_FUNCTION_EX for vectorcall Python functions is extremely wasteful. These are its steps:

  1. CALL_FUNCTION_EX calls do_call_core with a args tuple and kwargs dict.
  2. Eventually it's detected that the function supports vectorcall, and it calls _PyVectorcall_Call. This calls _PyStack_UnpackDict, which unpacks the args tuple and kwargs dict into a C array.
  3. This C array is passed to the vectorcall function. Eventually calling _PyEval_Vector.
  4. _PyEval_Vector calls _PyEvalFramePushAndInit, which sees that there's complex args, and recreates the tuple and args dict in initialize_locals from the C array.
  5. Frame is pushed and evaluated, then popped. End.

We shouldn't even be converting the arguments to a C array just to vectorcall. We should instead directly transfer ownership of args tuple and kwds dict because that would be significantly faster in this case (and save us the tuple and dict recreation dance).

CC @markshannon and @brandtbucher .

Vorherrschende Sprache
Python
Sterne
77.2k
Forks
36k
Ø Merge
1 T. 9 Std.
Gemergte PRs (30 T.)
558

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python/cpython

Alle Issues in python/cpython

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

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