From 3414b1ed457af85306e70045bdd30fa1dec193f6 Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Mon, 26 Aug 2024 14:00:13 +0100 Subject: [PATCH] Remove the PyFrame_FastToLocals and PyFrame_LocalsToFast calls from the trampoline `call_target`. Fix #336 --- pyinstrument/low_level/stat_profile.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pyinstrument/low_level/stat_profile.c b/pyinstrument/low_level/stat_profile.c index 0e03d57a..ebf1bb0f 100644 --- a/pyinstrument/low_level/stat_profile.c +++ b/pyinstrument/low_level/stat_profile.c @@ -232,7 +232,9 @@ stat_profile_init(void) static PyObject * call_target(ProfilerState *pState, PyFrameObject *frame, int what, PyObject *arg) { - PyFrame_FastToLocals(frame); + // note: we no longer call PyFrame_FastToLocals and PyFrame_LocalsToFast + // here, as it's only needed for python-level modification of locals, + // which a profiler doesn't need to do. #if PY_VERSION_HEX >= 0x03090000 // vectorcall implementation could be faster, is available in Python 3.9 @@ -242,10 +244,9 @@ call_target(ProfilerState *pState, PyFrameObject *frame, int what, PyObject *arg PyObject *result = PyObject_CallFunctionObjArgs(pState->target, (PyObject *) frame, whatstrings[what], arg == NULL ? Py_None : arg, NULL); #endif - PyFrame_LocalsToFast(frame, 1); - - if (result == NULL) + if (result == NULL) { PyTraceBack_Here(frame); + } return result; }