python / python/cpython

Move type checks from switch cases to beginning of `_Py_Specialize_BinaryOp`

未关闭
#128,310 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

interpreter-core type-feature
主要语言
Python
星标
77.2k
派生
36k
PR 合并指标
PR 指标待抓取

描述

Feature or enhancement

Proposal:

_Py_Specialize_BinaryOp: https://github.com/python/cpython/blob/aeb9b65aa26444529e4adc7d6e5b0d3dd9889ec2/Python/specialize.c#L2380-L2443
uses

if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) { 
    break; 
} 

check inside every switch case which is redundant. Placing this check before switch results in same performance but less generated code. Compiler with -O3 option seems to not recognize it. Attaching generated machine code (clang, apple silicon) for old and new versions
new.txt
old.txt

Feel free to close this if not worth it.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-128311

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

先检查 gh-128311,因为该 issue 链接到了已经在进行中的工作。然后阅读 Python/specialize.c 中的 _Py_Specialize_BinaryOp,并比较所附的 old.txt 和 new.txt 编译器输出;完成的标准是冗余检查得到一致处理,并且生成的代码产生预期结果。

由索引模型根据 Issue 内容生成。

评估

技术栈
c
领域
compilers, performance
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。