gh-123923: Defer refcounting for f_funcobj in _PyInterpreterFrame (#124026)

Use a `_PyStackRef` and defer the reference to `f_funcobj` when
possible. This avoids some reference count contention in the common case
of executing the same code object from multiple threads concurrently in
the free-threaded build.
This commit is contained in:
Sam Gross 2024-09-24 13:08:18 -07:00 committed by GitHub
parent d3c76dff44
commit f4997bb3ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 143 additions and 137 deletions

View file

@ -13,11 +13,8 @@ _PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg)
{
Py_VISIT(frame->frame_obj);
Py_VISIT(frame->f_locals);
Py_VISIT(frame->f_funcobj);
int err = _PyGC_VisitStackRef(&frame->f_executable, visit, arg);
if (err) {
return err;
}
_Py_VISIT_STACKREF(frame->f_funcobj);
_Py_VISIT_STACKREF(frame->f_executable);
return _PyGC_VisitFrameStack(frame, visit, arg);
}
@ -126,7 +123,7 @@ _PyFrame_ClearExceptCode(_PyInterpreterFrame *frame)
Py_DECREF(f);
}
_PyFrame_ClearLocals(frame);
Py_DECREF(frame->f_funcobj);
PyStackRef_CLEAR(frame->f_funcobj);
}
/* Unstable API functions */