CALL_FUNCTION_EX argument passing routine can be improved for vectorcalls

オープン
#95,757 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
リファクタリング
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
compilers

調査の方向性

do_call_core、_PyVectorcall_Call、_PyStack_UnpackDict、_PyEval_Vector、_PyEvalFramePushAndInit、initialize_locals を通る引数の流れを追跡します。まず、CALL_FUNCTION_EX が vectorcall の Python 関数に到達する仕組みと、各境界で所有権がどのように扱われるかを理解します。中間の C 配列と tuple/dict の再作成を経路から排除しつつ、引数の正しい所有権と動作を維持できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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 .

主要言語
Python
スター
77.2k
フォーク
36k
平均マージ
1日 9時間
マージ済み PR(30日)
558

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python/cpython のほかの issue

python/cpython の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。