python / python/cpython

_Py_atomic_add_*_relaxed

未关闭
#155,628 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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

描述

Feature or enhancement

Proposal:

I would like to add relaxed variants of the _Py_atomic_add functions.

The existing add operations are sequentially consistent, which is stronger (and on ARM, measurably more expensive) than necessary for uses like statistics counters and unique ID allocation, where the add must be atomic but does not need to order surrounding memory accesses.

Personally, I'd like to be able to use this in the CinderX JIT, but there are quite a few other places I found in the existing CPython codebase that could benefit from this set of functions:

  • the GC young.count allocation counter, which is purely heuristic and is already read with relaxed loads
  • lru_cache hit/miss statistics; the counters are already read with relaxed loads
  • the dict shared-keys incref which may only run while the caller already keeps the keys alive, and the final decref provides the ordering needed to free them
  • the module index allocator and the asyncio task name counter, where only uniqueness of the returned value matters
Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-155630

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先检查现有的 _Py_atomic_add 函数和关联的 PR gh-155630,然后比较列出的计数器和分配器使用场景与其在不对周围访问进行排序的情况下对原子性的需求。当 relaxed add 变体支持预期的使用场景且不削弱所需的原子行为时,工作即告完成。

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

评估

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

把新 issue 发到你的邮箱

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