python / python/cpython

pypy-style constant promotion to pool

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

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

interpreter-core topic-JIT type-feature
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ả

Proposal:

We should have a JIT constant pool and a JIT directive in the optimizer_bytecodes.c to promote certain values to constants. This would unlock significantly more future optimizations.

Steps needed:

  1. Add a constant pool to the executor object, so we can keep promoted constant alive. We already need this to unlock more constant propagation opportunities. The pool would be a PyListObject living in the vmdata field here https://github.com/python/cpython/blob/main/Include/internal/pycore_optimizer.h#L43 .
  2. Introduce a new optimizer macro: PROMOTE_TO_CONST_POOL and associated function promote_to_const_pool(ctx, obj) in optimizer_symbols.c. This macro will store any value it receives as a constant in the constant pool. This allows us to promote contants we see to the constant pool. This takes inspiration from RPython's hint(obj, promote=True)

What optimizations does this unlock?

  1. More constant propagation: we can now constant propagate not just immortal stuff but non-immortal things as well.
  2. Refcount removal. Anything in the the pool can use the cheaper _LOAD_CONST_INLINE_BORROW . Which will automatically benefit this work https://github.com/python/cpython/issues/134584 and vice versa. Ie, we automatically make it cheaper to load and store these values!
  3. On GIL/FT, we can promote method objects to the pool as well, which will allow us to perform more optimizations on them, such as LOAD_ATTR_METHOD folding.

We should also perhaps explore promoting globals to pool constants. Though that's a little risky, since we don't want to hold large objects around longer than needed.

The first PR should implement the first two steps and optimization 1. Optimization 2 should be a separate PR.

Linked PRs
  • gh-140968

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.

Hướng nghiên cứu

Bắt đầu với Include/internal/pycore_optimizer.h và trường vmdata của executor, sau đó kiểm tra optimizer_bytecodes.c và optimizer_symbols.c. PR đầu tiên hoàn tất khi executor có một constant pool PyListObject, PROMOTE_TO_CONST_POOL và promote_to_const_pool tồn tại, và các giá trị không immortal nhận được constant propagation; việc loại bỏ refcount được tách riêng một cách rõ ràng.

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

Đánh giá

Công nghệ
c
Lĩnh vực
compilers
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
Khá rõ ràng
Mức phù hợp với người mới
25/100

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.