Skip to content

Commit 747d402

Browse files
factor out tracing decision, try making _JIT faster
1 parent 4a0a530 commit 747d402

File tree

5 files changed

+28
-18
lines changed

5 files changed

+28
-18
lines changed

Include/internal/pycore_optimizer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ _PyJit_TryInitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame,
361361
int oparg, _PyExecutorObject *current_executor);
362362

363363
PyAPI_FUNC(void) _PyJit_FinalizeTracing(PyThreadState *tstate, int err);
364+
PyAPI_FUNC(bool) _PyJit_EnterExecutorShouldStopTracing(int og_opcode);
365+
364366
void _PyPrintExecutor(_PyExecutorObject *executor, const _PyUOpInstruction *marker);
365367
void _PyJit_TracerFree(_PyThreadStateImpl *_tstate);
366368

Modules/_testinternalcapi/test_cases.c.h

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

Python/bytecodes.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,8 +3118,8 @@ dummy_func(
31183118
#ifdef _Py_TIER2
31193119
bool is_resume = this_instr->op.code == RESUME_CHECK_JIT;
31203120
_Py_BackoffCounter counter = this_instr[1].counter;
3121-
if (!IS_JIT_TRACING() &&
3122-
(backoff_counter_triggers(counter) &&
3121+
if ((backoff_counter_triggers(counter) &&
3122+
!IS_JIT_TRACING() &&
31233123
(this_instr->op.code == JUMP_BACKWARD_JIT || is_resume)) &&
31243124
next_instr->op.code != ENTER_EXECUTOR) {
31253125
/* Back up over EXTENDED_ARGs so executor is inserted at the correct place */
@@ -3186,9 +3186,7 @@ dummy_func(
31863186
int og_opcode = executor->vm_data.opcode;
31873187
int og_oparg = (oparg & ~255) | executor->vm_data.oparg;
31883188
next_instr = this_instr;
3189-
// Continue tracing (skip over the executor). If it's a RESUME
3190-
// trace to form longer, more optimizeable traces.
3191-
if (og_opcode == RESUME_CHECK_JIT) {
3189+
if (_PyJit_EnterExecutorShouldStopTracing(og_opcode)) {
31923190
if (_PyOpcode_Caches[_PyOpcode_Deopt[opcode]]) {
31933191
PAUSE_ADAPTIVE_COUNTER(this_instr[1].counter);
31943192
}

Python/generated_cases.c.h

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

Python/optimizer.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,6 @@ _PyJit_translate_single_bytecode_to_trace(
632632
target--;
633633
}
634634

635-
// We want to trace over RESUME traces. Otherwise, functions with lots of RESUME
636-
// end up with many fragmented traces which perform badly.
637-
// See for example, the richards benchmark in pyperformance.
638635
if (opcode == ENTER_EXECUTOR) {
639636
_PyExecutorObject *executor = old_code->co_executors->executors[oparg & 255];
640637
opcode = executor->vm_data.opcode;
@@ -1104,6 +1101,19 @@ _PyJit_FinalizeTracing(PyThreadState *tstate, int err)
11041101
tracer->is_tracing = false;
11051102
}
11061103

1104+
bool
1105+
_PyJit_EnterExecutorShouldStopTracing(int og_opcode)
1106+
{
1107+
// Continue tracing (skip over the executor). If it's a RESUME
1108+
// trace to form longer, more optimizeable traces.
1109+
// We want to trace over RESUME traces. Otherwise, functions with lots of RESUME
1110+
// end up with many fragmented traces which perform badly.
1111+
// See for example, the richards benchmark in pyperformance.
1112+
// For consideration: We may want to consider tracing over side traces
1113+
// inserted into bytecode as well in the future.
1114+
return og_opcode == RESUME_CHECK_JIT;
1115+
}
1116+
11071117
void
11081118
_PyJit_TracerFree(_PyThreadStateImpl *_tstate)
11091119
{

0 commit comments

Comments
 (0)