Avoid refcounting on code objects during frame creation/destruction
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
The __code__ attribute of function objects is assignable.
As a consequence, frames must hold a strong reference to the code object in case the reference held by the function is lost.
Ideally, the __code__ attribute would be read-only, but to fix that would be a multi-year deprecation effort.
Until that happens, if ever, we can replace the strong reference with a borrowed reference to the code object as long as code object is guaranteed to outlive the frame.
Since the function will outlive the frame, if the function object keeps references to its prior __code__ attributes
when __code__ is assigned, then the code object will always outlive the frame.
This will need an extra field in each function, but the cost of one assignment to NULL during function creation, is much less than the cost of an incref and a decref on every call to that function.
The only downside is that in some obscure cases the lifetime of a few code objects will be extended.
Since the free-threading build makes all code objects immortal, this could actually be a big saving for the free-threading build.
Linked PRs
- gh-152955
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まずリンクされている PR gh-152955 を確認し、次に code 属性とフレームの作成・破棄に関連する関数オブジェクト、フレーム、コードオブジェクトを追跡してください。コードオブジェクトがフレームより長く存続することを証明しつつ、呼び出しごとの参照カウント操作を避け、関連する CPython テストが引き続き通過すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- リファクタリング
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100