Issue #29049: Call _PyObject_GC_TRACK() lazily when calling Python function.

Calling function is up to 5% faster.
This commit is contained in:
INADA Naoki 2016-12-24 20:19:08 +09:00
parent 2585443b6f
commit 5a625d0aa6
4 changed files with 45 additions and 15 deletions

View file

@ -415,7 +415,9 @@ frame_dealloc(PyFrameObject *f)
PyObject **p, **valuestack;
PyCodeObject *co;
PyObject_GC_UnTrack(f);
if (_PyObject_GC_IS_TRACKED(f))
_PyObject_GC_UNTRACK(f);
Py_TRASHCAN_SAFE_BEGIN(f)
/* Kill all local variables */
valuestack = f->f_valuestack;
@ -606,8 +608,8 @@ int _PyFrame_Init()
}
PyFrameObject* _Py_HOT_FUNCTION
PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
PyObject *locals)
_PyFrame_New_NoTrack(PyThreadState *tstate, PyCodeObject *code,
PyObject *globals, PyObject *locals)
{
PyFrameObject *back = tstate->frame;
PyFrameObject *f;
@ -727,10 +729,20 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
f->f_executing = 0;
f->f_gen = NULL;
_PyObject_GC_TRACK(f);
return f;
}
PyFrameObject*
PyFrame_New(PyThreadState *tstate, PyCodeObject *code,
PyObject *globals, PyObject *locals)
{
PyFrameObject *f = _PyFrame_New_NoTrack(tstate, code, globals, locals);
if (f)
_PyObject_GC_TRACK(f);
return f;
}
/* Block management */
void