GC: Implementation does not match behavior documented on `gc.set_threshold`
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
The documentation of gc.set_threshold states:
In order to decide when to run, the collector keeps track of the number object allocations and deallocations since the last collection. When the number of allocations minus the number of deallocations exceeds threshold0, collection starts
This doesn't seem to be accurate. Looking at the implementation, it appears that young.count is being used to track number of allocations minus the number of deallocations. However it doesn't actually track this due to the if (gcstate->young.count > 0) check here: https://github.com/python/cpython/blob/3.13/Python/gc.c#L2119.
As a concrete example, suppose threshold0=500. Suppose the GC runs and young.count is reset to 0, then 500 deallocations happen (by object ref counts dropping to 0), then 500 allocations happen. According to the documentation the GC would not run in this case, because the difference between allocations and deallocations is 0. However the actual tracked number in young.count will be 500, and GC will trigger.
I'm unsure which is the expected behavior; the documented one or the implemented one, but it does appear that the two do not currently agree.
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Linked PRs
- gh-156877
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 gc.set_threshold 的文件化行為以及 Python/gc.c 中約第 2119 行對 young.count 的處理開始。將回報的配置與解除配置情境與實作進行比較,然後檢視連結的 PR gh-156877;當實作與文件對預期的閾值行為達成一致時,即視為完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100