Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add a fast path to ``_Py_Dealloc()`` for non-GC objects. Patch by Donghee
Na.
26 changes: 24 additions & 2 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -3306,8 +3306,8 @@ next" object in the chain to 0. This can easily lead to stack overflows.
To avoid that, if the C stack is nearing its limit, instead of calling
dealloc on the object, it is added to a queue to be freed later when the
stack is shallower */
void
_Py_Dealloc(PyObject *op)
static Py_NO_INLINE void
Comment thread
corona10 marked this conversation as resolved.
py_dealloc(PyObject *op)
{
PyTypeObject *type = Py_TYPE(op);
unsigned long gc_flag = type->tp_flags & Py_TPFLAGS_HAVE_GC;
Expand Down Expand Up @@ -3372,6 +3372,28 @@ _Py_Dealloc(PyObject *op)
}
}

/*
* gh-130706: Keep the GC/reftracer path in the non-inlined py_dealloc().
* Inlining it makes the compiler save callee-saved registers at entry,
* so the non-GC objects path would have unnecessary register spills.
*/
void
Comment thread
corona10 marked this conversation as resolved.
_Py_Dealloc(PyObject *op)
{
#if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS)
// gh-130706: Avoid unnecessary register spills for non-GC objects.
PyTypeObject *type = Py_TYPE(op);
if (_PyRuntime.ref_tracer.tracer_func == NULL
&& !(type->tp_flags & Py_TPFLAGS_HAVE_GC))
{
type->tp_dealloc(op);
return;
}
#endif
// GC objects (trashcan), reftracer set, or debug builds.
py_dealloc(op);
}


PyObject **
PyObject_GET_WEAKREFS_LISTPTR(PyObject *op)
Expand Down
Loading