Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Reduced lock contention during LOAD_GLOBAL bytecode specialization under
free threading.
8 changes: 8 additions & 0 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,14 @@ _Py_Specialize_LoadGlobal(
PyObject *globals, PyObject *builtins,
_Py_CODEUNIT *instr, PyObject *name)
{
#ifdef Py_GIL_DISABLED
Comment thread
hawkinsp marked this conversation as resolved.
if (PyMutex_IsLocked(&globals->ob_mutex) || PyMutex_IsLocked(&builtins->ob_mutex)) {
// Skip specialization if either dictionary is locked to avoid lock
// contention.
unspecialize(instr);
return;
}
#endif
Py_BEGIN_CRITICAL_SECTION2(globals, builtins);
specialize_load_global_lock_held(globals, builtins, instr, name);
Py_END_CRITICAL_SECTION2();
Expand Down
Loading