Skip to content

GH-147985: Use lock-free lookup in PySet_Contains().#147986

Merged
kumaraditya303 merged 2 commits intopython:mainfrom
nascheme:gh-147985-pyset-contains-lockfree
Apr 3, 2026
Merged

GH-147985: Use lock-free lookup in PySet_Contains().#147986
kumaraditya303 merged 2 commits intopython:mainfrom
nascheme:gh-147985-pyset-contains-lockfree

Conversation

@nascheme
Copy link
Copy Markdown
Member

@nascheme nascheme commented Apr 1, 2026

Make PySet_Contains() attempt a lock-free lookup, similar to set.__contains__(). This avoids acquiring the set object mutex in the normal case.

@nascheme nascheme added type-feature A feature request or enhancement performance Performance or resource usage topic-free-threading labels Apr 1, 2026
@nascheme nascheme changed the title Use lock-free lookup in PySet_Contains(). GH--147985: Use lock-free lookup in PySet_Contains(). Apr 1, 2026
@nascheme nascheme changed the title GH--147985: Use lock-free lookup in PySet_Contains(). GH-147985: Use lock-free lookup in PySet_Contains(). Apr 1, 2026
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2026-04-01-12-35-55.gh-issue-147985.YVirHJ.rst Outdated
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The implementation uses set_lookkey_threadsafe() which is safe on Free Threading.

@nascheme nascheme marked this pull request as ready for review April 2, 2026 16:07
@nascheme nascheme requested a review from rhettinger as a code owner April 2, 2026 16:07
@kumaraditya303 kumaraditya303 merged commit 9d087d6 into python:main Apr 3, 2026
60 of 62 checks passed
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance or resource usage topic-free-threading type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants