python / python/cpython

_Py_atomic_add_*_relaxed

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

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

extension-modules interpreter-core performance type-feature
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Feature or enhancement

Proposal:

I would like to add relaxed variants of the _Py_atomic_add functions.

The existing add operations are sequentially consistent, which is stronger (and on ARM, measurably more expensive) than necessary for uses like statistics counters and unique ID allocation, where the add must be atomic but does not need to order surrounding memory accesses.

Personally, I'd like to be able to use this in the CinderX JIT, but there are quite a few other places I found in the existing CPython codebase that could benefit from this set of functions:

  • the GC young.count allocation counter, which is purely heuristic and is already read with relaxed loads
  • lru_cache hit/miss statistics; the counters are already read with relaxed loads
  • the dict shared-keys incref which may only run while the caller already keeps the keys alive, and the final decref provides the ordering needed to free them
  • the module index allocator and the asyncio task name counter, where only uniqueness of the returned value matters
Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-155630

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

Trước tiên, hãy xem xét các hàm _Py_atomic_add hiện có và PR liên quan gh-155630, sau đó so sánh các trường hợp sử dụng counter và allocator được liệt kê với nhu cầu về tính nguyên tử mà không cần sắp xếp thứ tự các truy cập xung quanh. Công việc hoàn tất khi các biến thể relaxed của add hỗ trợ các trường hợp sử dụng dự kiến mà không làm suy yếu hành vi nguyên tử bắt buộc.

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
performance
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
30/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.