| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Leverage `_Py_atomic_compare_exchange_ssize` to "claim" a single index position for each thread
|
(AI report on the performance / overall change) Free-threaded (--disable-gil) memory-safety fix for struct.Struct.iter_unpack. The fixOn the free-threaded build, unpackiter_iternext claims each record's slot with ThreadSanitizer verificationBuild: --with-thread-sanitizer --disable-gil --with-pydebug. Reproducer: 8
$ TSAN_OPTIONS="halt_on_error=1" PYTHON_GIL=0 ./python.exe repro.py survived this run # after fix: multiple full rounds, exit 0, no warnings 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.
|
Sorry, something went wrong.
|
This is not worth the complexity. See the issue. |
Sorry, something went wrong.
|
@ZeroIntensity this pattern seemed quite common and the solution to use the threaded serializer seems to come with a very high performance penalty |
Sorry, something went wrong.
|
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). |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Leverage _Py_atomic_compare_exchange_ssize to "claim" a single index position for each thread