Skip to content

Commit

Permalink
gh-128691: Use deferred reference counting on _thread._local (#128693)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
colesbury authored Jan 10, 2025
1 parent 087bb48 commit c141748
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit c141748

Please sign in to comment.