GC: Implementation does not match behavior documented on `gc.set_threshold`
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với hành vi được ghi trong tài liệu của gc.set_threshold và cách xử lý young.count trong Python/gc.c quanh dòng 2119. So sánh kịch bản cấp phát và giải phóng được báo cáo với phần triển khai, sau đó xem xét PR được liên kết gh-156877; được coi là hoàn tất khi phần triển khai và tài liệu thống nhất về hành vi ngưỡng dự kiến.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100