python / python/cpython

`queue.SimpleQueue.__sizeof__()` ignores the underlying data structure

オープン
#140,025 コメント 3 件 リアクション 1 件 担当者 0 名 GitHub で見る

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

extension-modules type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

queue.SimpleQueue (C level) uses a list on Python < 3.13[1][2][3][4], a ring buffer on Python >= 3.13[5][6]. However, it does not implement its own __sizeof__() method, and as a result, only the size of the simplequeueobject structure itself (basicsize) is taken as the size of the object, while the size of the underlying structure is ignored.

>>> from queue import SimpleQueue
>>> q = SimpleQueue()
>>> q.__sizeof__()
72  # 56 on Python < 3.13
>>> for _ in range(1_000):
...     q.put(object())
...     
>>> q.__sizeof__()
72  # 56 on Python < 3.13

Expected (should be, on Python >= 3.13):

>>> from queue import SimpleQueue
>>> q = SimpleQueue()
>>> q.__sizeof__()
136  # == 72 + 8*8 == sizeof(simplequeueobject) + sizeof(PyObject *)*INITIAL_RING_BUF_CAPACITY
>>> for _ in range(1_000):
...     q.put(object())
...     
>>> q.__sizeof__()
8264  # == 72 + 8*1024 == sizeof(simplequeueobject) + sizeof(PyObject *)*pow(2, ceil(log2(1000)))
CPython versions tested on:

3.9, 3.10, 3.11, 3.12, 3.13, 3.14

Operating systems tested on:

Linux

Linked PRs
  • gh-140086
  • gh-143137
  • gh-143277

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

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

はじめの一歩

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

調査の方向性

Modules/_queuemodule.c から始め、報告書でリンクされている SimpleQueue の実装と、そのサイズ計算に焦点を当てます。関連する Python バージョン全体で提供された再現手順を実行し、その後、報告されたサイズに基盤となるリストまたはリングバッファが含まれており、指定された期待値と一致することを確認します。

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

評価

技術スタック
c, python
領域
devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

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

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