Smaller objects for the free-threading build using smaller integer types for refcount
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
The literature on reference counting for JVM and other GCs show that very few reference counts get to more than 7. This matches up with our stats that should the ratio of refcount ops to object allocations is about 6/7 to 1.
With that in mind, it would make sense to make the C ints used to represent refcounts smaller.
Instead of:
uint32_t ob_ref_local; // local reference count
Py_ssize_t ob_ref_shared; // shared (atomic) reference count
we can use:
uint8_t ob_ref_local; // local reference count
uint32_t ob_ref_shared; // shared (atomic) reference count
using 5 bytes instead of 12.
If ob_ref_local would overflow, we can atomically move some of that count into ob_ref_shared.
if (++op->ob_ref_local == 0) {
atomic_add(&op->ob_ref_shared, 128);
op->ob_ref_local = 128;
}
ob_ref_shared can use the same approach to saturation and immortality that the default build currently does.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
未指定文件或测试名称。先从 free-threading 构建中 ob_ref_local 和 ob_ref_shared 的定义与使用开始,然后追踪引用计数溢出、原子更新、饱和以及不朽行为。完成的标准是:更小的布局能够正常工作,同时不改变引用计数的正确性或所述的溢出行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, python
- 领域
- performance
- Issue 类型
- 重构
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100