Skip to content

Commit 64f3468

Browse files
Address review
1 parent 598d332 commit 64f3468

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

Include/internal/pycore_optimizer.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extern "C" {
3636

3737
/* Exit quality thresholds: trace stops when fitness < exit_quality.
3838
* Higher = trace is more willing to stop here. */
39-
#define EXIT_QUALITY_CLOSE_LOOP (FITNESS_INITIAL)
39+
#define EXIT_QUALITY_CLOSE_LOOP (FITNESS_INITIAL - AVG_SLOTS_PER_INSTRUCTION*4)
4040
#define EXIT_QUALITY_ENTER_EXECUTOR (FITNESS_INITIAL * 3 / 8)
4141
#define EXIT_QUALITY_DEFAULT (FITNESS_INITIAL / 8)
4242
#define EXIT_QUALITY_SPECIALIZABLE (FITNESS_INITIAL / 80)
@@ -48,13 +48,9 @@ extern "C" {
4848
/* Heuristic backward-edge exit quality: leave room for about 1 unroll and
4949
* N_BACKWARD_SLACK more bytecodes before reaching EXIT_QUALITY_CLOSE_LOOP,
5050
* based on AVG_SLOTS_PER_INSTRUCTION. */
51-
#define N_BACKWARD_SLACK 50
51+
#define N_BACKWARD_SLACK 10
5252
#define EXIT_QUALITY_BACKWARD_EDGE (EXIT_QUALITY_CLOSE_LOOP / 2 - N_BACKWARD_SLACK * AVG_SLOTS_PER_INSTRUCTION)
5353

54-
/* Backward edge penalty for JUMP_BACKWARD_NO_INTERRUPT (coroutines/yield-from).
55-
* Smaller than FITNESS_BACKWARD_EDGE since we want to trace through them. */
56-
#define EXIT_QUALITY_BACKWARD_EDGE_COROUTINE (EXIT_QUALITY_BACKWARD_EDGE / 8)
57-
5854
/* Penalty for a perfectly balanced (50/50) branch.
5955
* 7 such branches (after per-slot cost) exhaust fitness to EXIT_QUALITY_DEFAULT.
6056
* The calculation assumes the branches are spread out roughly equally throughout the trace.

Python/optimizer.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -614,25 +614,19 @@ static inline int32_t
614614
compute_exit_quality(_Py_CODEUNIT *target_instr, int opcode,
615615
const _PyJitTracerState *tracer)
616616
{
617-
// We need to check for this, otherwise the first instruction (JUMP_BACKWARD usually)
618-
// is mistakenly thought of as an exit.
619-
if (uop_buffer_length((_PyJitUopBuffer *)&tracer->code_buffer) > CODE_SIZE_NO_PROGRESS) {
620-
if (target_instr == tracer->initial_state.start_instr ||
621-
target_instr == tracer->initial_state.close_loop_instr) {
622-
return EXIT_QUALITY_CLOSE_LOOP;
623-
}
624-
else if (target_instr->op.code == ENTER_EXECUTOR && !_PyJit_EnterExecutorShouldStopTracing(opcode)) {
625-
return EXIT_QUALITY_ENTER_EXECUTOR;
626-
}
627-
else if (opcode == JUMP_BACKWARD_JIT || opcode == JUMP_BACKWARD) {
628-
return EXIT_QUALITY_BACKWARD_EDGE;
629-
}
630-
else if (opcode == JUMP_BACKWARD_NO_INTERRUPT) {
631-
return EXIT_QUALITY_BACKWARD_EDGE_COROUTINE;
632-
}
633-
else if (_PyOpcode_Caches[_PyOpcode_Deopt[opcode]] > 0) {
634-
return EXIT_QUALITY_SPECIALIZABLE;
635-
}
617+
if (target_instr == tracer->initial_state.close_loop_instr) {
618+
return EXIT_QUALITY_CLOSE_LOOP;
619+
}
620+
else if (target_instr->op.code == ENTER_EXECUTOR && !_PyJit_EnterExecutorShouldStopTracing(opcode)) {
621+
return EXIT_QUALITY_ENTER_EXECUTOR;
622+
}
623+
else if (opcode == JUMP_BACKWARD_JIT ||
624+
opcode == JUMP_BACKWARD ||
625+
opcode == JUMP_BACKWARD_NO_INTERRUPT) {
626+
return EXIT_QUALITY_BACKWARD_EDGE;
627+
}
628+
else if (_PyOpcode_Caches[_PyOpcode_Deopt[opcode]] > 0) {
629+
return EXIT_QUALITY_SPECIALIZABLE;
636630
}
637631
return EXIT_QUALITY_DEFAULT;
638632
}

0 commit comments

Comments
 (0)