Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Include/internal/pycore_interp_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,8 @@ struct _is {
// Initialized to _PyEval_EvalFrameDefault().
_PyFrameEvalFunction eval_frame;
int eval_frame_allow_specialization;
// Perf wraps the default evaluator and permits prepared frame entry.
int eval_frame_is_perf;

PyFunction_WatchCallback func_watchers[FUNC_MAX_WATCHERS];
// One bit is set for each non-NULL entry in func_watchers
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Reduce the overhead of the perf trampoline. Its evaluator now tail-calls the
trampoline, and specialized Python calls and generator resumes stay enabled
while it is active.
217 changes: 191 additions & 26 deletions Modules/_testinternalcapi/test_cases.c.h

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Modules/_testinternalcapi/test_targets.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 44 additions & 2 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -4548,7 +4548,11 @@ dummy_func(
}

op(_CHECK_PEP_523, (--)) {
DEOPT_IF(IS_PEP523_HOOKED(tstate));
bool hooked = IS_PEP523_HOOKED(tstate);
#if TIER_ONE
hooked = hooked && !tstate->interp->eval_frame_is_perf;
#endif
DEOPT_IF(hooked);
}

op(_CHECK_FUNCTION_EXACT_ARGS, (callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
Expand Down Expand Up @@ -4584,11 +4588,17 @@ dummy_func(
}

op(_PUSH_FRAME, (new_frame -- )) {
assert(!IS_PEP523_HOOKED(tstate));
_PyInterpreterFrame *temp = PyStackRef_Unwrap(new_frame);
DEAD(new_frame);
SAVE_STACK();
assert(temp->previous == frame || temp->previous->previous == frame);
#if TIER_ONE
if (IS_PEP523_HOOKED(tstate)) {
frame = temp;
goto eval_frame_with_hook;
}
#endif
assert(!IS_PEP523_HOOKED(tstate));
CALL_STAT_INC(inlined_py_calls);
frame = tstate->current_frame = temp;
tstate->py_recursion_remaining--;
Expand Down Expand Up @@ -4716,6 +4726,8 @@ dummy_func(
_CHECK_PERIODIC_AT_END;

op(_CHECK_OBJECT, (type_version/2, callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
// The initializer cleanup shim requires inlined frame entry.
EXIT_IF(IS_PEP523_HOOKED(tstate));
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
EXIT_IF(!PyStackRef_IsNull(self_or_null));
EXIT_IF(!PyType_Check(callable_o));
Expand Down Expand Up @@ -6424,6 +6436,35 @@ dummy_func(
goto error;
}

spilled label(eval_frame_with_hook) {
_PyInterpreterFrame *callee = frame;
frame = tstate->current_frame;
assert(callee->previous == frame);
size_t return_offset = frame->return_offset;
bool is_generator = callee->owner == FRAME_OWNED_BY_GENERATOR;
callee->previous = NULL;
EVAL_CALL_STAT_INC(EVAL_CALL_TOTAL);
PyObject *result = tstate->interp->eval_frame(tstate, callee, 0);
// The evaluator can clear the callee. Read the return kind before
// another call can change it.
bool yielded = is_generator &&
((_PyThreadStateImpl *)tstate)->generator_return_kind == GENERATOR_YIELD;
if (result == NULL) {
RELOAD_STACK();
goto error;
}
assert(tstate->current_frame == frame);
_PyFrame_StackPush(frame, PyStackRef_FromPyObjectSteal(result));
RELOAD_STACK();
assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER);
LOAD_IP(yielded ? 1 + INLINE_CACHE_ENTRIES_SEND : return_offset);
LLTRACE_RESUME_FRAME();
#if _Py_TAIL_CALL_INTERP
int opcode;
#endif
DISPATCH();
}

label(error) {
_PyFrame_StackAssertInvalid(frame);
/* Double-check exception status. */
Expand Down Expand Up @@ -6647,6 +6688,7 @@ dummy_func(

}
dispatch_opcode:
eval_frame_with_hook:
error:
exception_unwind:
exit_unwind:
Expand Down
37 changes: 32 additions & 5 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading