python / python/cpython

_Py_atomic_add_*_relaxed

オープン
#155,628 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず既存の _Py_atomic_add 関数と関連する PR gh-155630 を確認し、次に、列挙されたカウンターおよびアロケーターのユースケースについて、周辺アクセスの順序付けを行わない原子性が必要かどうかを比較します。relaxed add のバリアントが意図されたユースケースをサポートし、必要なアトミック動作を弱めない状態になれば作業は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c
領域
performance
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。