python / python/cpython

Remove `DELETE_FAST` bytecode instruction

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

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

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

説明

DELETE_FAST has two uses:

  1. delete var where var is a local variable
  2. Cleaning up at the end of a named exception block.

A local variable can be deleted with the sequence PUSH_NULL; STORE_FAST var.

Deleting a local variable

Instead of DELETE_FAST n we can emit LOAD_FAST n; POP_TOP n; PUSH_NULL; STORE_FAST n which the bytecode optimizer will reduce to PUSH_NULL; STORE_FAST n in most cases.

Cleaning up at the end of a named exception block.

We currently emit the sequence: LOAD_CONST None; STORE_FAST n; DELETE_FAST n
which can be replaced with PUSH_NULL; STORE_FAST n

This case is far more common than explicitly deleting a local variable, so we can reduce code size as well as freeing up an opcode.


See https://github.com/faster-cpython/ideas/issues/490

Linked PRs
  • gh-145983

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

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

はじめの一歩

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

調査の方向性

まず、ローカル変数の削除と名前付き例外のクリーンアップのために DELETE_FAST を出力するコンパイラのエントリポイントを追跡します。それらのバイトコード出力を、提案されている PUSH_NULL; STORE_FAST シーケンスと比較し、その後 DELETE_FAST が出力されなくなっていることと、既存のバイトコードテストが引き続きパスすることを確認します。この issue では、関連する PR gh-145983 が参照されています。

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

評価

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

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

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