pypy-style constant promotion to pool
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- PR マージ指標
- PR 指標を取得中
説明
Proposal:
We should have a JIT constant pool and a JIT directive in the optimizer_bytecodes.c to promote certain values to constants. This would unlock significantly more future optimizations.
Steps needed:
- Add a constant pool to the executor object, so we can keep promoted constant alive. We already need this to unlock more constant propagation opportunities. The pool would be a
PyListObjectliving in the vmdata field here https://github.com/python/cpython/blob/main/Include/internal/pycore_optimizer.h#L43 . - Introduce a new optimizer macro:
PROMOTE_TO_CONST_POOLand associated functionpromote_to_const_pool(ctx, obj)inoptimizer_symbols.c. This macro will store any value it receives as a constant in the constant pool. This allows us to promote contants we see to the constant pool. This takes inspiration from RPython'shint(obj, promote=True)
What optimizations does this unlock?
- More constant propagation: we can now constant propagate not just immortal stuff but non-immortal things as well.
- Refcount removal. Anything in the the pool can use the cheaper
_LOAD_CONST_INLINE_BORROW. Which will automatically benefit this work https://github.com/python/cpython/issues/134584 and vice versa. Ie, we automatically make it cheaper to load and store these values! - On GIL/FT, we can promote method objects to the pool as well, which will allow us to perform more optimizations on them, such as LOAD_ATTR_METHOD folding.
We should also perhaps explore promoting globals to pool constants. Though that's a little risky, since we don't want to hold large objects around longer than needed.
The first PR should implement the first two steps and optimization 1. Optimization 2 should be a separate PR.
Linked PRs
- gh-140968
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Include/internal/pycore_optimizer.h と executor の vmdata フィールドから始め、次に optimizer_bytecodes.c と optimizer_symbols.c を調べます。最初の PR は、executor が PyListObject の定数プールを持ち、PROMOTE_TO_CONST_POOL と promote_to_const_pool が存在し、非イモータル値に定数伝播が適用されるようになった時点で完了です。refcount の削除は明確に別です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100