python / python/cpython

JIT: Set the IP and check for invalidation in `POP_TOP` only if `Py_Dealloc` is called.

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

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

3.16 interpreter-core performance topic-JIT type-feature
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

The optimizer removes many POP_TOPs, but quite a few remain.

The code for POP_TOP looks like this:

    inst(POP_TOP, (value --)) {
        PyStackRef_XCLOSE(value);
    }

which is fine for the interprete but in the JIT, as POP_TOP is marked as escaping, we need to set the IP before and check for invalidation afterwards.

What we could do, is have a version of POP_TOP that sets the IP and checks for invalidation only if Py_Dealloc is called, so we don't need to add SET_IP and CHECK_VALIDITY.

The new form of POP_TOP would look like this:

    op(_POP_TOP_SET_IP_CHECK_INVALID, (value --)) {
        if (do_decref_and_refcnt_is_zero(value)) {
            SET_IP()
            Py_Dealloc()
            CHECK_VALID();
        }
   }

_POP_TOP_SET_IP_CHECK_INVALID should be inserted in the same pass that we insert _SET_IP and _CHECK_VALIDITY as we know whether we need to insert those uops, and leave POP_TOP alone in those cases.

Overall, this should speed things up as it doesn't increase the overall code size, but it does execute less code in many cases.

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

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

はじめの一歩

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

調査の方向性

POP_TOP の JIT 実装と、_SET_IP および _CHECK_VALIDITY を挿入するパスを調査します。do_decref_and_refcnt_is_zero と、既存の SET_IP、Py_Dealloc、CHECK_VALID の各パスを追跡します。完了条件は、特殊化された形式が必要な箇所にのみ挿入され、その他の箇所では POP_TOP が変更されず、無効化の動作が維持されることです。

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

評価

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

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

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