Skip to content

Commit 564677c

Browse files
fix recursive generators slowdown
1 parent fafd6c0 commit 564677c

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Python/optimizer.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,15 @@ _PyJit_translate_single_bytecode_to_trace(
10061006
ADD_TO_TRACE(guard_ip, 0, (uintptr_t)next_instr, 0);
10071007
}
10081008
if (is_first_instr && _tstate->jit_tracer_state.prev_state.code_curr_size > CODE_SIZE_NO_PROGRESS) {
1009+
// If this is a trunk function trace and we end with a _JUMP_TO_TOP, and
1010+
// we push a frame at the end, that indicates we are unrolling recursion which is bad news.
1011+
// We need dynamic exit stitching to support such cases, but for now, this is disabled.
1012+
if (_PyOpcode_Deopt[_tstate->jit_tracer_state.initial_state.trace_origin_opcode] == RESUME &&
1013+
_tstate->jit_tracer_state.initial_state.exit == NULL && needs_guard_ip) {
1014+
trace_length = 0;
1015+
DPRINTF(2, "Trace is a function trace and heuristics indicate it's not likely worth it.\n");
1016+
goto done;
1017+
}
10091018
if (needs_guard_ip) {
10101019
ADD_TO_TRACE(_SET_IP, 0, (uintptr_t)next_instr, 0);
10111020
}

0 commit comments

Comments
 (0)