summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2025-04-07 18:13:02 (GMT)
committerGitHub <noreply@github.com>2025-04-07 18:13:02 (GMT)
commit1fcf409acef8a7a039353cf11a0bbb24ca6722f8 (patch)
tree1bdb6951ceb073e0f8ce1d6fec4aaa6c4a102e7b /Python
parentbd2f518555e8da6690757645e6b8dde932e1a41d (diff)
downloadcpython-1fcf409acef8a7a039353cf11a0bbb24ca6722f8.zip
cpython-1fcf409acef8a7a039353cf11a0bbb24ca6722f8.tar.gz
cpython-1fcf409acef8a7a039353cf11a0bbb24ca6722f8.tar.bz2
[3.13] gh-131988: Fix a multithreaded scaling regression (#131989)
gh-131988: Fix a multithreaded scaling regression The 3.13 free threaded build immortalizes certain objects to avoid reference count contention. In gh-127114 the condition was unintentionally changed to happen when the first thread was created instead of the first non-main thread. The `interp->gc.immortalize` field is then cleared again during `_PyGC_Init()`. Change the condition so that we check if we should immortalize objects using deferred reference counting whenever a non-main thread is created.
Diffstat (limited to 'Python')
-rw-r--r--Python/pystate.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 900cba0..5222a7e 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -1587,10 +1587,10 @@ new_threadstate(PyInterpreterState *interp, int whence)
HEAD_UNLOCK(interp->runtime);
#ifdef Py_GIL_DISABLED
- if (id == 1) {
+ if (id > 1) {
if (_Py_atomic_load_int(&interp->gc.immortalize) == 0) {
// Immortalize objects marked as using deferred reference counting
- // the first time a non-main thread is created.
+ // once a non-main thread is created, if we haven't already done so.
_PyGC_ImmortalizeDeferredObjects(interp);
}
}