Skip to content

Commit 98d7480

Browse files
author
wxue1
committed
Link to the compiled function to improve performance
When JIT is recording, backtrack the trace if encountering a compiled inline function and link to this function later. This reduces the runtime compilation overhead and duplicated JITTed code. Smaller code size has better cache efficiency, which brings 1.7% performance gain in our benchmark on x86. Signed-off-by: Wang, Xue <[email protected]> Signed-off-by: Yang, Lin A <[email protected]> Signed-off-by: Su, Tao <[email protected]>
1 parent bf727cf commit 98d7480

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ext/opcache/jit/zend_jit_vm_helpers.c

+15
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,14 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
562562
uint8_t trace_flags, op1_type, op2_type, op3_type;
563563
zend_class_entry *ce1, *ce2;
564564
const zend_op *link_to_enter_opline = NULL;
565+
/* Remember the first opline of inline function*/
566+
const zend_op *link_to_inline_func_opline = NULL;
565567
int backtrack_link_to_enter = -1;
566568
int backtrack_recursion = -1;
567569
int backtrack_ret_recursion = -1;
568570
int backtrack_ret_recursion_level = 0;
571+
/* Remember the index of inline function opline in the trace buffer */
572+
int backtrack_link_to_inline_func = -1;
569573
int loop_unroll_limit = 0;
570574
int last_loop = -1;
571575
int last_loop_level = -1;
@@ -922,6 +926,12 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
922926
} else if (count >= JIT_G(max_recursive_calls)) {
923927
stop = ZEND_JIT_TRACE_STOP_DEEP_RECURSION;
924928
break;
929+
/* If the inline function is JITTed, backtrack this trace. */
930+
} else if ( backtrack_link_to_inline_func < 0 && \
931+
(ZEND_OP_TRACE_INFO(opline, offset)->trace_flags & ZEND_JIT_TRACE_JITED)) {
932+
backtrack_link_to_inline_func = idx;
933+
link_to_inline_func_opline = opline;
934+
break;
925935
}
926936

927937
unrolled_calls[ret_level + level] = &EX(func)->op_array;
@@ -1156,6 +1166,11 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
11561166
ret_level = backtrack_ret_recursion_level;
11571167
stop = ZEND_JIT_TRACE_STOP_RECURSIVE_RET;
11581168
end_opline = orig_opline;
1169+
} else if (backtrack_link_to_inline_func > 0) {
1170+
/* Reset the index and stop flag to link to the compiled inline function. */
1171+
idx = backtrack_link_to_inline_func;
1172+
stop = ZEND_JIT_TRACE_STOP_LINK;
1173+
end_opline = link_to_inline_func_opline;
11591174
} else if (backtrack_link_to_enter > 0) {
11601175
if (stop == ZEND_JIT_TRACE_STOP_DEEP_RECURSION
11611176
&& zend_jit_trace_bad_stop_event(orig_opline, JIT_G(blacklist_root_trace) / 2) ==

0 commit comments

Comments
 (0)