python / python/cpython

Extend and improve `LOAD_COMMON_CONSTANT`

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

还没有人认领这个 Issue。

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

描述

Currently LOAD_COMMON_CONSTANT only loads 7 not-so-common constants and does so fairly inefficiently.

It could be improved in two ways:

  • Add some more constants, especially None, but also "", True, False and -1
  • Make the constants that it does load both statically allocated and immortal to avoid the pointer chasing and incref operation. Only any and all would need changing.

After some consideration, I think it best to leave the common constants table per interpreter, and not statically allocate them.

  • The changes to any and all may be breaking.
  • We also need to handle AssertionError and NotImplementedError will be tricky to make static

They should all be immortal though, and stored as _PyStackRefs not PyObject *s.

Linked PRs
  • gh-148971
  • gh-149625
  • gh-149688

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 LOAD_COMMON_CONSTANT 入口点开始,检查每个解释器的公共常量表如何存储和返回值。在更改设计之前查看相关 PR,尤其关注 _PyStackRef、永生性以及 any/all 方面的考虑。完成的标准是:已达成共识的公共常量(包括 None、空字符串、True、False 和 -1)都能得到处理,且不采用已被否决的静态分配方案。

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

评估

技术栈
python
领域
compilers
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

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