aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/gc_free_threading.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2025-03-26 14:38:47 -0400
committerGitHub <noreply@github.com>2025-03-26 14:38:47 -0400
commit67fbfb42bd5dfe861d0c58d9e6c48d8eef033d24 (patch)
tree282178fa55571c055c8327dc3d77fa6a882a404b /Python/gc_free_threading.c
parent3d4ac1a2c2b610f35a9e164878d67185e4a3546f (diff)
downloadcpython-67fbfb42bd5dfe861d0c58d9e6c48d8eef033d24.tar.gz
cpython-67fbfb42bd5dfe861d0c58d9e6c48d8eef033d24.zip
gh-131586: Avoid refcount contention in some "special" calls (#131588)
In the free threaded build, the `_PyObject_LookupSpecial()` call can lead to reference count contention on the returned function object becuase it doesn't use stackrefs. Refactor some of the callers to use `_PyObject_MaybeCallSpecialNoArgs`, which uses stackrefs internally. This fixes the scaling bottleneck in the "lookup_special" microbenchmark in `ftscalingbench.py`. However, the are still some uses of `_PyObject_LookupSpecial()` that need to be addressed in future PRs.
Diffstat (limited to 'Python/gc_free_threading.c')
-rw-r--r--Python/gc_free_threading.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Python/gc_free_threading.c b/Python/gc_free_threading.c
index 70dace9fe9e..4c459b02ce2 100644
--- a/Python/gc_free_threading.c
+++ b/Python/gc_free_threading.c
@@ -433,6 +433,12 @@ static void
gc_visit_thread_stacks(PyInterpreterState *interp, struct collection_state *state)
{
_Py_FOR_EACH_TSTATE_BEGIN(interp, p) {
+ _PyCStackRef *c_ref = ((_PyThreadStateImpl *)p)->c_stack_refs;
+ while (c_ref != NULL) {
+ gc_visit_stackref(c_ref->ref);
+ c_ref = c_ref->next;
+ }
+
for (_PyInterpreterFrame *f = p->current_frame; f != NULL; f = f->previous) {
if (f->owner >= FRAME_OWNED_BY_INTERPRETER) {
continue;