aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/generated_cases.c.h
diff options
context:
space:
mode:
authorTian Gao <gaogaotiantian@hotmail.com>2024-05-03 11:49:24 -0700
committerGitHub <noreply@github.com>2024-05-03 19:49:24 +0100
commit9c14ed06188aa4d462cd0fc4218c6023f9bf03cb (patch)
tree1e60a736e9b626706110a8f1600a20ef8c8b3827 /Python/generated_cases.c.h
parent998c3856c1e922ece806c162858dc587a1e92e02 (diff)
downloadcpython-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/generated_cases.c.h')
-rw-r--r--Python/generated_cases.c.h31
1 files changed, 16 insertions, 15 deletions
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 2a0f268ce6e..800d19229e3 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -3292,7 +3292,7 @@
INSTRUCTION_STATS(INSTRUMENTED_RESUME);
uintptr_t global_version = _Py_atomic_load_uintptr_relaxed(&tstate->eval_breaker) & ~_PY_EVAL_EVENTS_MASK;
uintptr_t code_version = FT_ATOMIC_LOAD_UINTPTR_ACQUIRE(_PyFrame_GetCode(frame)->_co_instrumentation_version);
- if (code_version != global_version) {
+ if (code_version != global_version && tstate->tracing == 0) {
if (_Py_Instrument(_PyFrame_GetCode(frame), tstate->interp)) {
goto error;
}
@@ -4948,20 +4948,18 @@
_Py_CODEUNIT *this_instr = next_instr - 1;
(void)this_instr;
assert(frame == tstate->current_frame);
- uintptr_t global_version =
- _Py_atomic_load_uintptr_relaxed(&tstate->eval_breaker) &
- ~_PY_EVAL_EVENTS_MASK;
- PyCodeObject *code = _PyFrame_GetCode(frame);
- uintptr_t code_version = FT_ATOMIC_LOAD_UINTPTR_ACQUIRE(code->_co_instrumentation_version);
- assert((code_version & 255) == 0);
- if (code_version != global_version) {
- int err = _Py_Instrument(code, tstate->interp);
- if (err) goto error;
- next_instr = this_instr;
- }
- else {
- if ((oparg & RESUME_OPARG_LOCATION_MASK) < RESUME_AFTER_YIELD_FROM) {
- CHECK_EVAL_BREAKER();
+ if (tstate->tracing == 0) {
+ uintptr_t global_version =
+ _Py_atomic_load_uintptr_relaxed(&tstate->eval_breaker) &
+ ~_PY_EVAL_EVENTS_MASK;
+ PyCodeObject* code = _PyFrame_GetCode(frame);
+ uintptr_t code_version = FT_ATOMIC_LOAD_UINTPTR_ACQUIRE(code->_co_instrumentation_version);
+ assert((code_version & 255) == 0);
+ if (code_version != global_version) {
+ int err = _Py_Instrument(_PyFrame_GetCode(frame), tstate->interp);
+ if (err) goto error;
+ next_instr = this_instr;
+ DISPATCH();
}
assert(this_instr->op.code == RESUME ||
this_instr->op.code == RESUME_CHECK ||
@@ -4973,6 +4971,9 @@
#endif /* ENABLE_SPECIALIZATION */
}
}
+ if ((oparg & RESUME_OPARG_LOCATION_MASK) < RESUME_AFTER_YIELD_FROM) {
+ CHECK_EVAL_BREAKER();
+ }
DISPATCH();
}