Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-146041: Avoid lock in sys.intern() for already interned strings#146072

Merged
colesbury merged 4 commits intopython:mainfrom
colesbury:gh-146041-intern-lock-free
Mar 24, 2026
Merged

gh-146041: Avoid lock in sys.intern() for already interned strings#146072
colesbury merged 4 commits intopython:mainfrom
colesbury:gh-146041-intern-lock-free

Conversation

@colesbury
Copy link
Contributor

@colesburycolesbury commentedMar 17, 2026
edited by bedevere-appbot
Loading

Fix free-threading scaling bottleneck in sys.intern andPyObject_SetAttr by avoiding the interpreter-wide lock when the string is already interned and immortalized.

@colesbury
Copy link
ContributorAuthor

@encukou, please let me know if you'd like me to do this differently. I've removed the assertion about unicode state in_Py_SetImmortalUntracked. It was awkward to keep because this PR requires that interned state is set toSSTATE_INTERNED_IMMORTAL as the last step in interning for thread-safety.

Copy link
Contributor

@mpagempage left a comment

Choose a reason for hiding this comment

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

Looks correct to me

PyObject *r;
int res = PyDict_GetItemRef(interned, s, &r);
if (res < 0) {
PyErr_Clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

Clearing the error here feels a little weird to me, but it's consistent with the rest of the function.

@colesburycolesbury added 🔨 test-with-refleak-buildbotsTest PR w/ refleak buildbots; report in status section needs backport to 3.14bugs and security fixes labelsMar 24, 2026
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@colesbury for commit6e59598 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F146072%2Fmerge

If you want to schedule another build, you need to add the🔨 test-with-refleak-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-refleak-buildbotsTest PR w/ refleak buildbots; report in status section labelMar 24, 2026
@colesburycolesbury merged commit6009309 intopython:mainMar 24, 2026
98 of 103 checks passed
@miss-islington-app
Copy link

Thanks@colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry,@colesbury, I could not cleanly backport this to3.14 due to a conflict.
Please backport usingcherry_picker on command line.

cherry_picker 60093096ba62110151d822b072a01061876e9404 3.14

@colesburycolesbury deleted the gh-146041-intern-lock-free branchMarch 24, 2026 18:29
colesbury added a commit to colesbury/cpython that referenced this pull requestMar 24, 2026
…ed strings (pythongh-146072)Fix free-threading scaling bottleneck in sys.intern and `PyObject_SetAttr` byavoiding the interpreter-wide lock when the string is already interned andimmortalized.(cherry picked from commit6009309)Co-authored-by: Sam Gross <colesbury@gmail.com>
@bedevere-app
Copy link

GH-146390 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelMar 24, 2026
@colesburycolesbury removed their assignmentMar 24, 2026
colesbury added a commit that referenced this pull requestMar 25, 2026
…ings (gh-146072) (#146390)Fix free-threading scaling bottleneck in sys.intern and `PyObject_SetAttr` byavoiding the interpreter-wide lock when the string is already interned andimmortalized.(cherry picked from commit6009309)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@mpagempagempage approved these changes

@ZeroIntensityZeroIntensityAwaiting requested review from ZeroIntensityZeroIntensity is a code owner

@AA-TurnerAA-TurnerAwaiting requested review from AA-TurnerAA-Turner is a code owner

@encukouencukouAwaiting requested review from encukou

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@colesbury@bedevere-bot@mpage

[8]ページ先頭

©2009-2026 Movatter.jp