`PyType_GetModuleByDef` is really slow.
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
PyType_GetModuleByDef does a lot of work for what was a single memory read prior to sub-interpreters.
For example, https://github.com/python/cpython/issues/114682.
We should provide a more efficient way to get to the module state from the module def.
AFAICT, the function to get the module state is a pure function of the interpreter and the module def.
Since the module def already has a m_index field that is described as "The module's index into its interpreter's modules_by_index cache.", then a Py_GetModuleFromDef() function could be as simple as:
inline PyObject *
Py_GetModuleFromDef(PyModuleDef *def)
{
return PyInterpreterState_Get()->modules_table[def->m_base.m_index];
}
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 PyType_GetModuleByDef、PyModuleDef.m_index 以及 issue 中提到的解释器 modules_by_index 缓存开始。将当前的查找路径与提议的 module-from-definition API 进行比较,并验证在处理所报告开销的同时,每个解释器中的行为仍然正确。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, python
- 领域
- backend-api-design, performance
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100