python / python/cpython

Remove `DELETE_FAST` bytecode instruction

未關閉
#145,749 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

3.15 interpreter-core performance
主要語言
Python
星號
77.2k
分支
36k
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. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 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 摘要。