You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Activity
terryjreedy commentedon Aug 12, 2026
This might need discussion on https://discuss.python.org/ idea channel. Lets see what others think.
dpdani commentedon Aug 17, 2026
@terryjreedy I don't think this needs discussion on DPO, it's a purely internal change.
pythongh-155628: Use a relaxed add for the asyncio task name counter
pythongh-155628: Add relaxed _Py_atomic_add_*
pythongh-155628: Use a relaxed add for the module index allocator
pythongh-155628: Use relaxed adds for the GC allocation counter
pythongh-155628: Use relaxed adds for the lru_cache hit/miss counters
pythongh-155628: Use a relaxed add for the asyncio task name counter
pythongh-155628: Add relaxed _Py_atomic_compare_exchange
pythongh-155628: Use relaxed compare_exchange for gc young count
pythongh-155628: Add relaxed _Py_atomic_add_*
pythongh-155628: Use a relaxed add for the module index allocator
pythongh-155628: Use relaxed adds for the GC allocation counter
pythongh-155628: Use relaxed adds for the lru_cache hit/miss counters
pythongh-155628: Use a relaxed add for the asyncio task name counter
pythongh-155628: Add relaxed _Py_atomic_compare_exchange
pythongh-155628: Use relaxed compare_exchange for gc young count
gh-155628: Add _Py_atomic_add_*_relaxed variants (#155630)