Repository navigation
Conversation
In the free-threaded build, dequeiter_next(), dequereviter_next() and dequeiter_reduce() entered a two-object critical section on the iterator and its deque. All writes to the iterator's state already happen while holding the deque's lock, so the deque's critical section alone is enough to serialize concurrent next() calls on a shared iterator. This halves the atomic read-modify-write operations per item. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refs #161850.
Serialize forward and reverse deque iteration, and iterator reduction, using the deque's mutex alone. The iterator retains its deque throughout its lifetime, and its mutable iteration state is protected by that mutex. This removes the iterator mutex acquisition/release from the per-item path.
Changes
dequeiter_next(),dequereviter_next()anddequeiter_reduce().__length_hint__read.test_free_threading.test_collections.list(deque)take a critical section per item #161850.Test Plan
git diff --checkpass for this main-based branch.d0ed2da495922d2887672d3fd0c2cdeb22df4278, including ordinary/free-threaded builds and TSan jobs.On the tested 950, the 3.14.6 backport's 1000-element deque iteration benchmark decreased from about 52.3 to 30.6 microseconds. This is supporting evidence for the approach, not a performance claim for this branch.
AI tools assisted preparation of the change and submission text.