gh-117783: Immortalize objects that use deferred reference counting (#118112)
Deferred reference counting is not fully implemented yet. As a temporary measure, we immortalize objects that would use deferred reference counting to avoid multi-threaded scaling bottlenecks. This is only performed in the free-threaded build once the first non-main thread is started. Additionally, some tests, including refleak tests, suppress this behavior.
This commit is contained in:
@@ -1568,6 +1568,17 @@ new_threadstate(PyInterpreterState *interp, int whence)
|
||||
// Must be called with lock unlocked to avoid re-entrancy deadlock.
|
||||
PyMem_RawFree(new_tstate);
|
||||
}
|
||||
else {
|
||||
#ifdef Py_GIL_DISABLED
|
||||
if (interp->gc.immortalize.enable_on_thread_created &&
|
||||
!interp->gc.immortalize.enabled)
|
||||
{
|
||||
// Immortalize objects marked as using deferred reference counting
|
||||
// the first time a non-main thread is created.
|
||||
_PyGC_ImmortalizeDeferredObjects(interp);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef Py_GIL_DISABLED
|
||||
// Must be called with lock unlocked to avoid lock ordering deadlocks.
|
||||
|
||||
Reference in New Issue
Block a user