Inspect module is prohibitively expensive to import
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
From post by @AlexWaygood in https://github.com/python/cpython/issues/117372#issuecomment-2047024740_:
I'm a little dismayed that dataclasses adds so much overhead. Does that imply that dataclasses shouldn't be used in the stdlib?
dataclassesis an unfortunately heavy import, yes. Although it imports relatively few modules itself, one of those modules isinspect, which has a huge import time (inspectimports half the standard library). In the past, I've looked into removing thedataclassesdependency oninspect, but couldn't see a way to do so without making the code significantly more ugly; the same goes when it comes to improving the import time forinspectitself. (In hindsight, I'd argueinspectshould probably have been a package rather than a huge single-file Python module... but hindsight is 20/20.)
Perhaps inspect could be refactored to limit the import-time cost.
Currently on my m3 mac pro, on the second attempt, the import times are 1.2ms and 7.9ms (cumulative):
cpython main @ ./python.exe -X importtime -c 'import inspect' 2> /dev/null ; ./python.exe -X importtime -c 'import inspect' 2>1 | grep -E '(cumul|inspect)'
import time: self [us] | cumulative | imported package
import time: 1184 | 7892 | inspect
I've searched the issue tracker and didn't see anything tracking this concern, so right now it's a naïve feature request.
Related: https://github.com/python/cpython/issues/108901
Linked PRs
- gh-119526
- gh-119546
- gh-144756
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 lệnh inspect về thời gian import được nêu trong issue và xem xét module inspect, sử dụng đầu ra của Python's -X importtime để xác định chi phí import tích lũy của nó. Công việc được xem là hoàn tất khi refactor inspect để giảm overhead khi import mà vẫn giữ nguyên hành vi; các PR được liên kết cho biết công việc đó đã được triển khai.
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
- performance
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100