`sys.getsizeof()` does not include inline values
オープン
まだ誰も着手していません。
interpreter-core
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
Commit tested: 5e65a1acc0b
I have a program that allocates numerous instances of this type:
@dataclass
class Node:
cdr: Self | None
BIG_DATA = None
for i in range(50):
BIG_DATA = Node(BIG_DATA)
print(sys.getsizeof(BIG_DATA))
After the 28th iteration, I find that it stabilizes at printing 48. But if I run the program in GDB and trace the actual allocations, I see that it is allocating 80 bytes per iteration:
# Set a GDB-recognized breakpoint
os.kill(os.getpid(), signal.SIGTRAP)
# In GDB:
# b _PyObject_Malloc
# commands
# silent
# print nbytes
# continue
# end
for i in range(50):
BIG_DATA = Node(BIG_DATA)
I believe that the missing bytes can be accounted for in the inline values. I observe the same behavior on Python 3.13.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-128763
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
報告されている sys.getsizeof() の動作から始め、dataclass Node の例を再現し、その出力を GDB の _PyObject_Malloc トレースと比較します。inline 値がどのように計上されるかを調査します。例で示された割り当てを報告サイズが反映し、既存の動作を退行させなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend, performance
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100