-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-112529: Remove PyGC_Head from object pre-header in free-threaded build #114564
Conversation
…aded build This avoids allocating space for PyGC_Head in the free-threaded build. The GC implementation for free-threaded CPython does not use the PyGC_Head structure. * The trashcan mechanism uses the `ob_tid` field instead of `_gc_prev` in the free-threaded build. * The GDB libpython.py file now determines the offset of the managed dict field based on whether the running process is a free-threaded build. Those are identified by the `ob_ref_local` field in PyObject. * Fixes `_PySys_GetSizeOf()` which incorrectly incorrectly included the size of `PyGC_Head` in the size of static `PyTypeObject`.
if (!Py_IS_TYPE(o, &PyType_Type) || | ||
PyType_HasFeature((PyTypeObject *)o, Py_TPFLAGS_HEAPTYPE)) | ||
{ | ||
/* Add the size of the pre-header if "o" is not a static type */ | ||
presize = _PyType_PreHeaderSize(Py_TYPE(o)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now more closely matches the behavior of the Python check_sizeof
function, although that function does not account for space for managed dict/weakref.
This looks good to me. I think the comment beside It would be nice to have a bit more explanation of how Minor nit not really worth fixing: in libpython.py, I think the test could be |
Another change that is now possible but maybe should be separate from this PR: In There are a couple potentially hot paths outside of |
Added
Yeah, that's correct. I've added a comment in
That doesn't work because
Good point. I'll do that in a follow up PR. |
…aded build (python#114564) * pythongh-112529: Remove PyGC_Head from object pre-header in free-threaded build This avoids allocating space for PyGC_Head in the free-threaded build. The GC implementation for free-threaded CPython does not use the PyGC_Head structure. * The trashcan mechanism uses the `ob_tid` field instead of `_gc_prev` in the free-threaded build. * The GDB libpython.py file now determines the offset of the managed dict field based on whether the running process is a free-threaded build. Those are identified by the `ob_ref_local` field in PyObject. * Fixes `_PySys_GetSizeOf()` which incorrectly incorrectly included the size of `PyGC_Head` in the size of static `PyTypeObject`.
This avoids allocating space for
PyGC_Head
in the free-threaded build. The GC implementation for free-threaded CPython does not use thePyGC_Head
structure.ob_tid
field instead of_gc_prev
in the free-threaded build.ob_ref_local
field in PyObject._PySys_GetSizeOf()
, which incorrectly incorrectly included the size ofPyGC_Head
in the size of staticPyTypeObject
.--disable-gil
builds #112529