python / python/cpython

Smaller objects for the free-threading build using smaller integer types for refcount

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

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

3.16 interpreter-core performance topic-free-threading
主要言語
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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

ファイルもテストも指定されていません。まず free-threading ビルドにおける ob_ref_local と ob_ref_shared の定義と使用箇所から始め、次に参照カウントのオーバーフロー、アトミックな更新、飽和、イモータリティの動作を追跡してください。より小さいレイアウトが、参照カウントの正しさや記載されたオーバーフローの動作を変更せずに機能すれば完了です。

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

評価

技術スタック
c, python
領域
performance
issue の種類
リファクタリング
難易度
5/5
見積もり時間
1週間以上
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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