CALL_FUNCTION_EX argument passing routine can be improved for vectorcalls
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 36k
- Ø Merge
- 1 T. 9 Std.
- Gemergte PRs (30 T.)
- 558
Beschreibung
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:
CALL_FUNCTION_EXcallsdo_call_corewith aargstuple andkwargsdict.- Eventually it's detected that the function supports vectorcall, and it calls
_PyVectorcall_Call. This calls_PyStack_UnpackDict, which unpacks theargstuple andkwargsdict into a C array. - This C array is passed to the vectorcall function. Eventually calling
_PyEval_Vector. _PyEval_Vectorcalls_PyEvalFramePushAndInit, which sees that there's complex args, and recreates the tuple and args dict ininitialize_localsfrom the C array.- 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 .
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
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.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Refactoring
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100