summaryrefslogtreecommitdiffstats
path: root/Python/bytecodes.c
diff options
context:
space:
mode:
authorTian Gao <gaogaotiantian@hotmail.com>2024-05-03 18:49:24 (GMT)
committerGitHub <noreply@github.com>2024-05-03 18:49:24 (GMT)
commit9c14ed06188aa4d462cd0fc4218c6023f9bf03cb (patch)
tree1e60a736e9b626706110a8f1600a20ef8c8b3827 /Python/bytecodes.c
parent998c3856c1e922ece806c162858dc587a1e92e02 (diff)
downloadcpython-9c14ed06188aa4d462cd0fc4218c6023f9bf03cb.zip
cpython-9c14ed06188aa4d462cd0fc4218c6023f9bf03cb.tar.gz
cpython-9c14ed06188aa4d462cd0fc4218c6023f9bf03cb.tar.bz2
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/bytecodes.c')
-rw-r--r--Python/bytecodes.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 9769cfe..e8383ed 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -148,20 +148,18 @@ dummy_func(
tier1 inst(RESUME, (--)) {
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);
- ERROR_IF(err, 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);
+ ERROR_IF(err, error);
+ next_instr = this_instr;
+ DISPATCH();
}
assert(this_instr->op.code == RESUME ||
this_instr->op.code == RESUME_CHECK ||
@@ -173,6 +171,9 @@ dummy_func(
#endif /* ENABLE_SPECIALIZATION */
}
}
+ if ((oparg & RESUME_OPARG_LOCATION_MASK) < RESUME_AFTER_YIELD_FROM) {
+ CHECK_EVAL_BREAKER();
+ }
}
inst(RESUME_CHECK, (--)) {
@@ -189,7 +190,7 @@ dummy_func(
inst(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)) {
ERROR_NO_POP();
}
@@ -4284,7 +4285,7 @@ dummy_func(
#endif
uintptr_t eval_breaker = _Py_atomic_load_uintptr_relaxed(&tstate->eval_breaker);
DEOPT_IF(eval_breaker & _PY_EVAL_EVENTS_MASK);
- assert(eval_breaker == FT_ATOMIC_LOAD_UINTPTR_ACQUIRE(_PyFrame_GetCode(frame)->_co_instrumentation_version));
+ assert(tstate->tracing || eval_breaker == FT_ATOMIC_LOAD_UINTPTR_ACQUIRE(_PyFrame_GetCode(frame)->_co_instrumentation_version));
}
// END BYTECODES //