Re: Optimizing assembly for spl_object_id(), fdiv(), etc in the JIT?
| From: | tyson andre | Date: | Sat, 25 Apr 2020 17:38:30 +0000 |
| Subject: | Re: Optimizing assembly for spl_object_id(), fdiv(), etc in the JIT? | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109849@lists.php.net to get a copy of this message | ||
Hi Nikita,
> Our general approach to this is to first add a VM opcode for the operation,
> which will also provide a benefit if the JIT is not used.
> There's already plenty of those, see ZEND_STRLEN for example.
> Adding JIT support for the opcode would then be the natural second step.
I've seen those - I'd assume there'd be a long tail of functions such as preg_match()
without references, spl_object_id(), substr(), etc, that are called frequently, but not often enough
to have their own opcodes.
What about adding a new opcode types that combines INIT_FCALL, SEND_VAR (or SEND_VAL for constants),
and DO_ICALL for known internal functions?
Has that been proposed before?
This could be used when the arguments were inferred by opcache to have correct types.
```
Old (in function where $x is known to be a non-reference object):
0001 INIT_FCALL 1 96 string("spl_object_id")
0002 SEND_VAR CV0($x) 1
0003 V2 = DO_ICALL
0004 T1 = INIT_ARRAY 1 (packed) CV0($x) V2
0005 RETURN T1
New (after opcache):
0001 T1 = INIT_AND_DO_ICALL_1_ARG $x // op1=$x, op2 is unused, extended_value = enum value
corresponding to spl_object_id()
0002 RETURN T1
```
And fdiv() could become INIT_AND_DO_ICALL_2_ARG $x $y op1=$x, op2 is $y, extended_value = enum
value corresponding to fdiv
This should give opcache the information it needs to continue tracking the definitions and uses of
variables, as well as function return types.
- I'd hope there'd be a performance improvement, due to not needing to look up
zend_function, using the native C stack for zvals instead of a dynamic stack, perform param type
checks, etc.
This would only accept constants and compiled variables of known good types for functions that
wouldn't emit notices or cause re-entry - temporary values (e.g.
spl_object_id(some_function())) wouldn't be accepted.
The C implementation for the new opcode could be a switch on extended_value with enum values for
dozens of commonly used functions
that weren't common enough for individual opcodes.
Thanks,
- Tyson