Allow storing the instruction offset as an alternative to the instruction pointer in the frame.
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Feature or enhancement
Proposal:
The CPython JIT compiler, and other compilers like CinderX, need to keep the current frame's instruction pointer up-to-date so that code introspecting the frame can determine the location that is currently being executed.
Before 3.11, the instruction offset was stored in the frame and this is still the value that Python code sees, frame.f_lasti, but it is inefficient to repeatedly calculate an offset in the interpreter, so internally we store the pointer and calculate the offset lazily when needed.
A JIT, however, does not want to maintain an instruction pointer, as it has to store the pointer every time that a call can escape. Instead or storing a 64 bit pointer, it is more efficient to store a 16 bit offset.
Also, with free-threading, it is impossible for the JIT to store a pointer, as it depends on the thread local bytecode.
Given that the interpreter wants to store pointers, and the JIT needs offsets, we can either:
- Use offsets everywhere
- Use a mix of offsets and pointers
(1) would slow down the interpreter significantly, so is undesirable
(2) gets us the best of both, in terms of performance, but is a bit more complex.
I think option 2, is the best.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先追蹤 CPython 的框架表示方式,以及以 frame.f_lasti 公開的指令偏移量的處理方式,接著檢視直譯器目前如何維護其 Instruction Pointer。當 JIT 能夠維護偏移量,而直譯器仍能繼續使用指標(包括在 free-threading 下),且不會遺失框架內省可見的位置時,這項變更就完成了。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- compilers, performance
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100