Improved performance and arguably simpler code for dictionaries by changing the keys layout
未关闭
还没有人认领这个 Issue。
interpreter-core
performance
type-feature
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Current layout
Currently the _dictkeysobject struct is laid out like this:
ptr ----> +--------------+
| header |
+--------------+
| indices |
+--------------+
| keys |
+--------------+
which requires some relatively expensive calculation to find the start of the keys, as the indices are not only variable in number, but variable in size also.
Proposed layout
If instead it is laid out as follows:
+--------------+
| indices |
ptr ----> +--------------+
| header |
+--------------+
| keys |
+--------------+
and the indices laid from highest to lowest with 0 just before ptr, finding the start of the keys is as simple as ptr->keys . Accessing an index is no slower, and the code barely any more complex.
Linked PRs
- gh-145097
- gh-150640
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先查看提议的 _dictkeysobject 布局以及关联的 PR gh-145097 和 gh-150640,因为工作已经转移到那里。比较当前和提议的 index、header 和 keys 排列;要完成这项工作,需要实现新布局,并通过性能或正确性验证来支持它。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 重构
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100