Allow storing the instruction offset as an alternative to the instruction pointer in the frame.
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- 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