diff options
author | Tian Gao <gaogaotiantian@hotmail.com> | 2024-05-03 11:49:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-03 19:49:24 +0100 |
commit | 9c14ed06188aa4d462cd0fc4218c6023f9bf03cb (patch) | |
tree | 1e60a736e9b626706110a8f1600a20ef8c8b3827 /Python/ceval.c | |
parent | 998c3856c1e922ece806c162858dc587a1e92e02 (diff) | |
download | cpython-9c14ed06188aa4d462cd0fc4218c6023f9bf03cb.tar.gz cpython-9c14ed06188aa4d462cd0fc4218c6023f9bf03cb.zip |
gh-107674: Improve performance of `sys.settrace` (GH-117133)
* Check tracing in RESUME_CHECK
* Only change to RESUME_CHECK if not tracing
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 59498bc826e..11874690990 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -808,17 +808,23 @@ resume_frame: { _Py_CODEUNIT *prev = frame->instr_ptr; _Py_CODEUNIT *here = frame->instr_ptr = next_instr; - _PyFrame_SetStackPointer(frame, stack_pointer); - int original_opcode = _Py_call_instrumentation_line( - tstate, frame, here, prev); - stack_pointer = _PyFrame_GetStackPointer(frame); - if (original_opcode < 0) { - next_instr = here+1; - goto error; - } - next_instr = frame->instr_ptr; - if (next_instr != here) { - DISPATCH(); + int original_opcode = 0; + if (tstate->tracing) { + PyCodeObject *code = _PyFrame_GetCode(frame); + original_opcode = code->_co_monitoring->lines[(int)(here - _PyCode_CODE(code))].original_opcode; + } else { + _PyFrame_SetStackPointer(frame, stack_pointer); + original_opcode = _Py_call_instrumentation_line( + tstate, frame, here, prev); + stack_pointer = _PyFrame_GetStackPointer(frame); + if (original_opcode < 0) { + next_instr = here+1; + goto error; + } + next_instr = frame->instr_ptr; + if (next_instr != here) { + DISPATCH(); + } } if (_PyOpcode_Caches[original_opcode]) { _PyBinaryOpCache *cache = (_PyBinaryOpCache *)(next_instr+1); |