CALL_FUNCTION_EX argument passing routine can be improved for vectorcalls

Đang mở
#95,757 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
compilers

Hướng nghiên cứu

Theo dõi luồng đối số qua do_call_core, _PyVectorcall_Call, _PyStack_UnpackDict, _PyEval_Vector, _PyEvalFramePushAndInit và initialize_locals. Trước tiên, hãy hiểu cách CALL_FUNCTION_EX đến được các hàm Python vectorcall và quyền sở hữu được xử lý như thế nào tại mỗi ranh giới. Công việc được xem là hoàn tất khi đường đi tránh được mảng C trung gian và việc tạo lại tuple/dict, đồng thời vẫn bảo toàn quyền sở hữu đối số chính xác và hành vi đúng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

interpreter-core performance type-feature

While working on https://github.com/python/cpython/issues/95126, I noticed that CALL_FUNCTION_EX for vectorcall Python functions is extremely wasteful. These are its steps:

  1. CALL_FUNCTION_EX calls do_call_core with a args tuple and kwargs dict.
  2. Eventually it's detected that the function supports vectorcall, and it calls _PyVectorcall_Call. This calls _PyStack_UnpackDict, which unpacks the args tuple and kwargs dict into a C array.
  3. This C array is passed to the vectorcall function. Eventually calling _PyEval_Vector.
  4. _PyEval_Vector calls _PyEvalFramePushAndInit, which sees that there's complex args, and recreates the tuple and args dict in initialize_locals from the C array.
  5. Frame is pushed and evaluated, then popped. End.

We shouldn't even be converting the arguments to a C array just to vectorcall. We should instead directly transfer ownership of args tuple and kwds dict because that would be significantly faster in this case (and save us the tuple and dict recreation dance).

CC @markshannon and @brandtbucher .

Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
558

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/cpython

Tất cả issue của python/cpython

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.