Avoid refcounting on code objects during frame creation/destruction
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ả
The __code__ attribute of function objects is assignable.
As a consequence, frames must hold a strong reference to the code object in case the reference held by the function is lost.
Ideally, the __code__ attribute would be read-only, but to fix that would be a multi-year deprecation effort.
Until that happens, if ever, we can replace the strong reference with a borrowed reference to the code object as long as code object is guaranteed to outlive the frame.
Since the function will outlive the frame, if the function object keeps references to its prior __code__ attributes
when __code__ is assigned, then the code object will always outlive the frame.
This will need an extra field in each function, but the cost of one assignment to NULL during function creation, is much less than the cost of an incref and a decref on every call to that function.
The only downside is that in some obscure cases the lifetime of a few code objects will be extended.
Since the free-threading build makes all code objects immortal, this could actually be a big saving for the free-threading build.
Linked PRs
- gh-152955
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 bằng cách xem xét PR được liên kết gh-152955, sau đó truy vết các đối tượng hàm, frame và đối tượng code liên quan đến thuộc tính code cũng như việc tạo và hủy frame. Công việc được xem là hoàn tất khi chứng minh được rằng các đối tượng code tồn tại lâu hơn các frame của chúng mà không cần thực hiện thao tác đếm tham chiếu cho mỗi lần gọi, đồng thời các bài kiểm thử CPython liên quan vẫn vượt qua.
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
- Tái cấu trúc
- Độ 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
- 30/100