gh-154013: Add free-threading test for shared struct.iter_unpack#154141
gh-154013: Add free-threading test for shared struct.iter_unpack#154141johng wants to merge 1 commit into
Conversation
Leverage `_Py_atomic_compare_exchange_ssize` to "claim" a single index position for each thread
|
(AI report on the performance / overall change) Free-threaded ( The fixOn the free-threaded build, ThreadSanitizer verificationBuild:
PerformanceEnvironment. Apple Silicon (arm64), macOS; 6 performance cores / 18 logical. Single-threaded hot path (ns per element, min of 12 runs)Lower is better. Relative overhead is largest for a 1-field struct (least work
No measurable single-threaded regression (within run-to-run noise). Multi-threaded throughput (Melem/s, higher is better)Three workloads, three variants — all measured in one run:
Takeaways.
|
|
This is not worth the complexity. See the issue. |
|
@ZeroIntensity this pattern seemed quite common and the solution to use the threaded serializer seems to come with a very high performance penalty |
|
Do you have real-world examples where people would benefit from fast, concurrent iteration here? The primary issue with the concurrent iteration pattern is that the order in which items are returned to each thread is non-deterministic; a thread has to somehow know where it is in the iterator (which is impossible to do safely without external locking) or not care about the position of the iterator, which is not a common occurrence, and there are usually better patterns (such as distributing items to worker threads sequentially, rather than letting each of them access the iterator). |
Leverage
_Py_atomic_compare_exchange_ssizeto "claim" a single index position for each thread