Skip to content

Commit 20afb79

Browse files
committed
gh-130706: Add a fast path to _Py_Dealloc() for non-GC objects.
1 parent e580c88 commit 20afb79

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add a fast path to ``_Py_Dealloc()`` for non-GC objects. Patch by Donghee
2+
Na.

‎Objects/object.c‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3306,8 +3306,8 @@ next" object in the chain to 0. This can easily lead to stack overflows.
33063306
To avoid that, if the C stack is nearing its limit, instead of calling
33073307
dealloc on the object, it is added to a queue to be freed later when the
33083308
stack is shallower */
3309-
void
3310-
_Py_Dealloc(PyObject *op)
3309+
static Py_NO_INLINE void
3310+
dealloc_general(PyObject *op)
33113311
{
33123312
PyTypeObject *type = Py_TYPE(op);
33133313
unsigned long gc_flag = type->tp_flags & Py_TPFLAGS_HAVE_GC;
@@ -3372,6 +3372,22 @@ _Py_Dealloc(PyObject *op)
33723372
}
33733373
}
33743374

3375+
void
3376+
_Py_Dealloc(PyObject *op)
3377+
{
3378+
#if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS)
3379+
// gh-130706: Remove unnecessary stack frame for non-GC objects.
3380+
PyTypeObject *type = Py_TYPE(op);
3381+
if (_PyRuntime.ref_tracer.tracer_func == NULL
3382+
&& !(type->tp_flags & Py_TPFLAGS_HAVE_GC))
3383+
{
3384+
type->tp_dealloc(op);
3385+
return;
3386+
}
3387+
#endif
3388+
dealloc_general(op);
3389+
}
3390+
33753391

33763392
PyObject **
33773393
PyObject_GET_WEAKREFS_LISTPTR(PyObject *op)

0 commit comments

Comments
 (0)