Skip to content

Commit f547880

Browse files
Fix a few perf regressions due to tracing thru optimizer
1 parent 278bbe6 commit f547880

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

Python/optimizer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,9 @@ _PyJit_translate_single_bytecode_to_trace(
865865

866866
operand = 0;
867867
if (frame->owner < FRAME_OWNED_BY_INTERPRETER) {
868-
if (new_func != NULL) {
868+
// Don't add nested code objects to the dependency.
869+
// It causes endless re-traces.
870+
if (new_func != NULL && !(new_code->co_flags & CO_NESTED)) {
869871
operand = (uintptr_t)new_func;
870872
DPRINTF(2, "Adding %p func to op\n", (void *)operand);
871873
_Py_BloomFilter_Add(dependencies, new_func);

Python/optimizer_bytecodes.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,14 @@ dummy_func(void) {
752752
}
753753

754754
op(_PY_FRAME_KW, (callable, self_or_null, args[oparg], kwnames -- new_frame)) {
755-
new_frame = PyJitRef_NULL;
756-
ctx->done = true;
755+
assert((this_instr + 2)->opcode == _PUSH_FRAME);
756+
PyCodeObject *co = get_code_with_logging((this_instr + 2));
757+
if (co == NULL) {
758+
ctx->done = true;
759+
break;
760+
}
761+
762+
new_frame = PyJitRef_Wrap((JitOptSymbol *)frame_new(ctx, co, 0, NULL, 0));
757763
}
758764

759765
op(_CHECK_AND_ALLOCATE_OBJECT, (type_version/2, callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
@@ -882,16 +888,16 @@ dummy_func(void) {
882888
ctx->curr_frame_depth++;
883889
stack_pointer = ctx->frame->stack_pointer;
884890
uint64_t operand = this_instr->operand0;
885-
if (operand == 0 || (operand & 1)) {
886-
// It's either a code object or NULL
891+
if (operand == 0) {
887892
ctx->done = true;
888893
break;
889894
}
890-
PyFunctionObject *func = (PyFunctionObject *)operand;
891-
PyCodeObject *co = (PyCodeObject *)func->func_code;
892-
_Py_BloomFilter_Add(dependencies, co);
893-
assert(PyFunction_Check(func));
894-
ctx->frame->func = func;
895+
if (!(operand & 1)) {
896+
PyFunctionObject *func = (PyFunctionObject *)operand;
897+
PyCodeObject *co = (PyCodeObject *)func->func_code;
898+
_Py_BloomFilter_Add(dependencies, co);
899+
ctx->frame->func = func;
900+
}
895901
}
896902

897903
op(_UNPACK_SEQUENCE, (seq -- values[oparg], top[0])) {

Python/optimizer_cases.c.h

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

0 commit comments

Comments
 (0)