summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2025-01-10 00:59:10 (GMT)
committerGitHub <noreply@github.com>2025-01-10 00:59:10 (GMT)
commitc1417487e98e270d614965ed78ff9439044b65a6 (patch)
tree9c1956881d668247a9daee46e9abc6058e0ba36e
parent087bb48acac997c06e69dae25bae2dd75194b980 (diff)
downloadcpython-c1417487e98e270d614965ed78ff9439044b65a6.zip
cpython-c1417487e98e270d614965ed78ff9439044b65a6.tar.gz
cpython-c1417487e98e270d614965ed78ff9439044b65a6.tar.bz2
gh-128691: Use deferred reference counting on `_thread._local` (#128693)
This change, along with the LOAD_ATTR specializations, makes the "thread_local_read" micro benchmark in Tools/ftscalingbench/ftscalingbench.py scale well to multiple threads.
-rw-r--r--Modules/_threadmodule.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 2cbdfeb..d19ae32 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -1414,6 +1414,10 @@ local_new(PyTypeObject *type, PyObject *args, PyObject *kw)
return NULL;
}
+ // gh-128691: Use deferred reference counting for thread-locals to avoid
+ // contention on the shared object.
+ _PyObject_SetDeferredRefcount((PyObject *)self);
+
self->args = Py_XNewRef(args);
self->kw = Py_XNewRef(kw);