Skip to content

Commit fafd6c0

Browse files
make RESUME tracing a single attempt
1 parent 2373aee commit fafd6c0

4 files changed

Lines changed: 24 additions & 16 deletions

File tree

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,11 +2993,13 @@ dummy_func(
29932993
}
29942994
// For some reason, RESUME_CHECK_JIT is quite expensive compared to RESUME.
29952995
// It's enough to show up as a 10-20% slowdown in some benchmarks!
2996-
// For that reason, we replace it back with RESUME immediately.
2996+
// For that reason, we replace it back with RESUME_CHECK immediately.
2997+
// This also means that function entry tracing is practically a single attempt.
29972998
// In JIT builds, we thus stick only to RESUME and wait for it to specialize to RESUME_CHECK_JIT.
2998-
// This amkes RESUME slightly slower, but since the JIT is faster it makes up for it.
2999+
// This makes RESUME slightly slower on JIT builds, but since the JIT is faster it makes up for it.
29993000
if (is_resume) {
3000-
FT_ATOMIC_STORE_UINT8_RELAXED(this_instr->op.code, RESUME);
3001+
FT_ATOMIC_STORE_UINT8_RELAXED(this_instr->op.code, RESUME_CHECK);
3002+
FT_ATOMIC_STORE_UINT16_RELAXED(this_instr[1].counter, initial_resume_backoff_counter());
30013003
}
30023004
#endif
30033005
}

Python/ceval.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,16 +1468,16 @@ stop_tracing_and_jit(PyThreadState *tstate, _PyInterpreterFrame *frame)
14681468
// Deal with backoffs
14691469
_PyExitData *exit = _tstate->jit_tracer_state.initial_state.exit;
14701470
if (exit == NULL) {
1471-
// We hold a strong reference to the code object, so the instruction won't be freed.
1472-
if (err <= 0) {
1473-
_Py_BackoffCounter counter = _tstate->jit_tracer_state.initial_state.trace_enter_instr[1].counter;
1474-
_tstate->jit_tracer_state.initial_state.trace_enter_instr[1].counter = restart_backoff_counter(counter);
1475-
}
1476-
else {
1477-
int origin_opcode = _tstate->jit_tracer_state.initial_state.trace_origin_opcode;
1478-
assert(origin_opcode == JUMP_BACKWARD_JIT || origin_opcode == RESUME_CHECK_JIT);
1479-
_tstate->jit_tracer_state.initial_state.trace_enter_instr[1].counter = origin_opcode == JUMP_BACKWARD_JIT
1480-
? initial_jump_backoff_counter() : initial_resume_backoff_counter();
1471+
int origin_opcode = _tstate->jit_tracer_state.initial_state.trace_origin_opcode;
1472+
if (origin_opcode == JUMP_BACKWARD_JIT) {
1473+
// We hold a strong reference to the code object, so the instruction won't be freed.
1474+
if (err <= 0) {
1475+
_Py_BackoffCounter counter = _tstate->jit_tracer_state.initial_state.trace_enter_instr[1].counter;
1476+
_tstate->jit_tracer_state.initial_state.trace_enter_instr[1].counter = restart_backoff_counter(counter);
1477+
}
1478+
else {
1479+
_tstate->jit_tracer_state.initial_state.trace_enter_instr[1].counter = initial_jump_backoff_counter();
1480+
}
14811481
}
14821482
}
14831483
else {

Python/generated_cases.c.h

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)