Commit 4fd24bc
gh-NNNNN: Make _STORE_ATTR_SLOT lock-free on the free-threaded build
Replace the LOCK_OBJECT / atomic-release-store / UNLOCK_OBJECT sequence
in _STORE_ATTR_SLOT (and the matching critical section in
PyMember_SetOne for Py_T_OBJECT_EX / _Py_T_OBJECT) with a single atomic
exchange on the slot pointer. Atomic exchange returns a unique old
value per writer, so Py_XDECREF cannot double-free across concurrent
writers. Concurrent readers (_LOAD_ATTR_SLOT, PyMember_GetOne) already
use atomic load + _Py_TryIncrefCompare; PyMember_GetOne's locked
fallback is replaced by _Py_XGetRef so it also stays correct against
lock-free writers.
Drops HAS_DEOPT_FLAG from _STORE_ATTR_SLOT (no LOCK can fail anymore),
which removes one _DEOPT exit per occurrence from Tier 2 traces. Adds
_Py_atomic_exchange_ptr to the cases-generator's NON_ESCAPING_FUNCTIONS
allowlist so the generator stops wrapping it in
_PyFrame_SetStackPointer / _GetStackPointer.
Adds a concurrent _Py_T_OBJECT test (test_T_OBJECT in test_slots.py).
Benchmarks (PGO+LTO, taskset -c 4, pyperf):
micro_store_attr_slot 79.0 ns -> 54.5 ns 1.45x faster
micro_attr_idiv 180 ns -> 149 ns 1.21x faster
bm_float 87.4 ms -> 83.7 ms 1.04x faster
bm_nbody (control) unchanged
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 9df2b6c commit 4fd24bc
9 files changed
Lines changed: 77 additions & 54 deletions
File tree
- Include/internal
- Lib/test/test_free_threading
- Modules/_testinternalcapi
- Python
- Tools/cases_generator
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3225 | 3225 | | |
3226 | 3226 | | |
3227 | 3227 | | |
3228 | | - | |
3229 | 3228 | | |
3230 | 3229 | | |
| 3230 | + | |
| 3231 | + | |
| 3232 | + | |
| 3233 | + | |
| 3234 | + | |
| 3235 | + | |
| 3236 | + | |
| 3237 | + | |
3231 | 3238 | | |
3232 | | - | |
3233 | | - | |
3234 | | - | |
| 3239 | + | |
| 3240 | + | |
3235 | 3241 | | |
| 3242 | + | |
3236 | 3243 | | |
3237 | 3244 | | |
3238 | 3245 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
102 | 100 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
109 | 108 | | |
110 | | - | |
| 109 | + | |
| 110 | + | |
111 | 111 | | |
112 | | - | |
113 | 112 | | |
114 | | - | |
| 113 | + | |
115 | 114 | | |
116 | 115 | | |
117 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
118 | 125 | | |
119 | | - | |
120 | 126 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | 127 | | |
131 | 128 | | |
132 | 129 | | |
| |||
320 | 317 | | |
321 | 318 | | |
322 | 319 | | |
323 | | - | |
324 | | - | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
325 | 326 | | |
326 | | - | |
327 | | - | |
| 327 | + | |
| 328 | + | |
328 | 329 | | |
329 | 330 | | |
330 | 331 | | |
| |||
336 | 337 | | |
337 | 338 | | |
338 | 339 | | |
| 340 | + | |
339 | 341 | | |
340 | 342 | | |
341 | 343 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
700 | 700 | | |
701 | 701 | | |
702 | 702 | | |
| 703 | + | |
703 | 704 | | |
704 | 705 | | |
705 | 706 | | |
| |||
0 commit comments