-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use deferred reference counting in some _PyInterpreterFrame
fields
#123923
Labels
Comments
colesbury
added
type-feature
A feature request or enhancement
topic-free-threading
labels
Sep 10, 2024
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Sep 10, 2024
…terFrame` Use a `_PyStackRef` and defer the reference to `f_executable` 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.
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Sep 10, 2024
…terFrame` Use a `_PyStackRef` and defer the reference to `f_executable` 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.
colesbury
added a commit
that referenced
this issue
Sep 12, 2024
…me` (#123924) Use a `_PyStackRef` and defer the reference to `f_executable` 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.
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Sep 12, 2024
…Frame` 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.
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Sep 12, 2024
…Frame` 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.
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Sep 14, 2024
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Sep 20, 2024
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Sep 24, 2024
colesbury
added a commit
that referenced
this issue
Sep 24, 2024
…#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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feature or enhancement
The
_PyInterpreterFrame
struct contains a strong reference to:f_executable
- the currently executing code objectf_funcobj
- the function objectf_locals
- the locals object (often NULL)frame_obj
- the frame object (often NULL)We should use deferred references (in the free-threaded build) for
f_executable
andf_funcobj
because they are a common source of reference count contention. The pointed to objects (code and function) already support deferred reference counting, but the references in the frame are not deferred.I think we don't need to bother with changing
f_locals
for now. I don't think it's used frequently enough to be a bottleneck, but we can revisit it later if necessary.The
frame_obj
are typically unique -- not shared across threads -- so we don't need to bother with deferred reference counting forframe_obj
.Complications and hazards
_PyInterpreterFrame
are also embedded in generators/coroutines andPyFrameObject
, which are heap objects. We need to be careful that_PyStackRef
fields are visible to the GC in order to be kept alive. Once an object is untracked, the_PyStackRef
fields may no longer be valid: it's safe to callPyStackRef_CLOSE/CLEAR
but not otherwise access or dereference those fields because the GC may have already collected them.Linked PRs
f_executable
in_PyInterpreterFrame
#123924f_funcobj
in_PyInterpreterFrame
#124026The text was updated successfully, but these errors were encountered: