Skip to content

gh-152075: Avoid lock contention in _Py_Specialize_LoadGlobal under free threading (gh-153720) - #153720

Merged
colesbury merged 1 commit into
python:mainfrom
hawkinsp:contention
Jul 31, 2026
Merged

colesbury merged 1 commit into
python:mainfrom
hawkinsp:contention

Conversation

@hawkinsp

@hawkinsp hawkinsp commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Under high thread concurrency in free-threaded builds, _Py_Specialize_LoadGlobalsuffers from lock contention when acquiring the critical section mutexes for the globals and builtins dictionaries during bytecode specialization.

This PR skips LOAD_GLOBAL bytecode specialization if acquiring the two object mutexes would block.

@nascheme

Copy link
Copy Markdown
Member

CC @colesbury @mpage

@hawkinsp

Copy link
Copy Markdown
Contributor Author

@mpage or @colesbury ?

Comment thread Python/specialize.c
…nder free threading

Under high thread concurrency in free-threaded builds, `_Py_Specialize_LoadGlobal` suffers from lock contention when acquiring the critical section mutexes for the `globals` and `builtins` dictionaries during bytecode specialization.

This PR skips LOAD_GLOBAL bytecode specialization if acquiring the two object mutexes would block.
@colesbury

Copy link
Copy Markdown
Contributor

Thanks!

@colesbury colesbury changed the title gh-152075: Avoid lock contention in _Py_Specialize_LoadGlobal under free threading gh-152075: Avoid lock contention in _Py_Specialize_LoadGlobal under free threading (gh-153720) Jul 31, 2026
@colesbury
colesbury enabled auto-merge (squash) July 31, 2026 01:28
@colesbury
colesbury merged commit ac8ba0c into python:main Jul 31, 2026
57 checks passed
mbeijen pushed a commit to mbeijen/cpython that referenced this pull request Aug 14, 2026
…nder free threading (pythongh-153720)

Under high thread concurrency in free-threaded builds, `_Py_Specialize_LoadGlobal` suffers from lock contention when acquiring the critical section mutexes for the `globals` and `builtins` dictionaries during bytecode specialization.

This PR skips LOAD_GLOBAL bytecode specialization if acquiring the two object mutexes would block.
@kumaraditya303 kumaraditya303 added needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Oct 6, 2026
@miss-islington-app

Copy link
Copy Markdown

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

@miss-islington-app

Copy link
Copy Markdown

Thanks @hawkinsp for the PR, and @colesbury for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 6, 2026

Copy link
Copy Markdown

GH-158904 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 6, 2026
@bedevere-app

bedevere-app Bot commented Oct 6, 2026

Copy link
Copy Markdown

GH-158905 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Oct 6, 2026
kumaraditya303 pushed a commit that referenced this pull request Oct 6, 2026
…under free threading (gh-153720) (#158904)

gh-152075: Avoid lock contention in _Py_Specialize_LoadGlobal under free threading (gh-153720)

Under high thread concurrency in free-threaded builds, `_Py_Specialize_LoadGlobal` suffers from lock contention when acquiring the critical section mutexes for the `globals` and `builtins` dictionaries during bytecode specialization.

This PR skips LOAD_GLOBAL bytecode specialization if acquiring the two object mutexes would block.
(cherry picked from commit ac8ba0c)

Co-authored-by: Peter Hawkins <phawkins@google.com>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants