python / python/cpython

`_PyStaticCode_InternStrings` is called ~800 times during startup.

未关闭
#96,459 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

3.12 interpreter-core performance topic-subinterpreters type-bug
主要语言
Python
星标
77.2k
派生
36k
平均合并
1 天 9 小时
30 天内合并 PR
558

描述

The _Py_Deepfreeze_Init() function calls _PyStaticCode_InternStrings once for each string.

Creating the interned string dict in one go, from the table of static strings would be much faster.
something like this (error checking omitted, and other liberties taken for brevity)

_Py_CreateInternedDict(PyObject **strs, int n) {
   PyDictKeys *table = make_dict_keys(n);
   for (int i = 0; i < n; i++) {
        table->entries[i].key = table->entries[i].value = strs[i];
        table->entries[i].hashcode = strs[i].hash_code;
        // Fix up size and entries here.
   }
   return new_dict(table);
}

All the hash codes will need to be initialized first, but we probably should do that anyway.

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先跟踪 _Py_Deepfreeze_Init() 及其对 _PyStaticCode_InternStrings 的调用。检查 interned string dictionary 和字符串哈希码是如何初始化的,然后确定所提议的批量构建是否保留了所需的字典状态和启动行为。

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

评估

技术栈
c, python
领域
backend, performance
Issue 类型
重构
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

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