Method call on imported definition differs inside of a list comprehension
未关闭
还没有人认领这个 Issue。
interpreter-core
performance
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
import re
[x for x in [] if re.match(".*", x)]
vs:
import re
re.match(".*", x)
When you disassemble these you'll see the inlined one will be doing a LOAD_ATTR 3 (match + NULL|self) while the one outside of the comprehension will be doing a PUSH_NULL/CALL which is to disable the method call optimization on things which are likely not methods.
These should both have the same byte code. There's no perceivable code execution difference other than performance though.
CPython versions tested on:
3.12, CPython main branch
Operating systems tested on:
Linux
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先在 CPython 3.12 或 main 上对报告中的两个 Python 示例进行反汇编,然后跟踪列表推导式和顶层调用路径是如何编译的。完成的标准是两种形式都为导入定义的调用使用一致的字节码,同时不改变可观察行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 42/100