Improve performance of deepcopy by setting keep alive key in the memo
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ả
Feature or enhancement
Proposal:
In the deepcopy implementation an exception is generated when the memo dict does not contain a key id(memo). We can avoid generating an exception by adding this key when the memo is generated. As a consequence the _keep_alive method is just a single line of code and we can inline this.
There is a behavior change: a call deepcopy(x, {}) works with current main, but will raise an exception (since the key id(memo)) has not been set. This might be acceptable as the documentation states "The memo dictionary should be treated as an opaque object." (see https://docs.python.org/3/library/copy.html). And in the code itself the memo argument is not documented at all https://github.com/python/cpython/blob/9aea9c100fbbaa1437f595da65417204872106a9/Lib/copy.py#L3-L9
There are some unit tests involving the memo, but those seem to test the behavior of the deepcopy and not of the memo argument.
If the behavior change is not acceptable because memo is part of the public interface, should we then instead document the structure of the argument memo` as being an implementation detail?
The argument _nil as a sentinel to the deepcopy is redundant, as the memo can only contain integers so we can use None instead.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
- gh-123746
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 đọc Lib/copy.py và các unit test hiện có kiểm tra deepcopy với một memo. Xem xét PR được liên kết gh-123746 và xác định liệu hành vi của memo có phải là một thay đổi đối với giao diện công khai hay không; công việc được xem là hoàn tất khi phần triển khai được chọn, các test và mọi tài liệu cần thiết nhất quán xác định hành vi này.
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ính năng
- Độ 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
- 25/100