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

gh-152075: Avoid lock contention in _Py_Specialize_LoadGlobal under free threading (gh-153720)#153720
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
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.

3 participants