Skip to content

Commit a9c0805

Browse files
committed
Require 16 iterations before optimizing
This is needed so branch prediction can work.
1 parent 25bfb3d commit a9c0805

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Python/optimizer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,9 @@ translate_bytecode_to_trace(
559559
_Py_CODEUNIT *next_instr = instr + 1 + _PyOpcode_Caches[_PyOpcode_Deopt[opcode]];
560560
_Py_CODEUNIT *target_instr = next_instr + oparg;
561561
_Py_CODEUNIT *stub_target = jump_likely ? next_instr : target_instr;
562+
DPRINTF(4, "%s(%d): counter=%x, bitcount=%d, likely=%d, sense=%d, uopcode=%s\n",
563+
uop_name(opcode), oparg,
564+
counter, bitcount, jump_likely, jump_sense, uop_name(uopcode));
562565
ADD_TO_TRACE(uopcode, max_length, 0);
563566
ADD_TO_STUB(max_length, SAVE_IP, INSTR_IP(stub_target, code), 0);
564567
ADD_TO_STUB(max_length + 1, EXIT_TRACE, 0, 0);
@@ -938,6 +941,6 @@ PyUnstable_Optimizer_NewUOpOptimizer(void)
938941
opt->resume_threshold = UINT16_MAX;
939942
// Need at least 3 iterations to settle specializations.
940943
// A few lower bits of the counter are reserved for other flags.
941-
opt->backedge_threshold = 3 << OPTIMIZER_BITS_IN_COUNTER;
944+
opt->backedge_threshold = 16 << OPTIMIZER_BITS_IN_COUNTER;
942945
return (PyObject *)opt;
943946
}

0 commit comments

Comments
 (0)