#
d9510342 |
| 16-May-2020 |
Tyson Andre |
Optimize ZEND_COUNT opcodes on arrays in the jit Avoid the overhead of a call and checking types when the argument is definitely an array. Avoid the overhead of gc when `__destruct`
Optimize ZEND_COUNT opcodes on arrays in the jit Avoid the overhead of a call and checking types when the argument is definitely an array. Avoid the overhead of gc when `__destruct` won't get called. This seemed cheap enough to check for in the jit. Because of https://wiki.php.net/rfc/restrict_globals_usage we can be sure in the ZEND_COUNT handler that the array count does not have to be recomputed in php 8.1. The below example took 0.854 seconds before the optimization, and 0.564 seconds after the optimization, giving the same result ```php <?php /** @jit */ function bench_count(int $n): int { $total = 0; $arr = []; for ($i = 0; $i < $n; $i++) { $arr[] = $i; $total += count($arr); } return $total; } function main() { $n = 1000; $iterations = 50000; $start = microtime(true); $result = 0; for ($i = 0; $i < $iterations; $i++) { $result += bench_count($n); } $elapsed = microtime(true) - $start; printf("Total for n=%d, iterations=%d = %d, elapsed=%.3f\n", $n, $iterations, $result, $elapsed); } main(); ``` Before ```asm mov $0x7feb8cf8a858, %r15 mov $ZEND_COUNT_SPEC_CV_UNUSED_HANDLER, %rax call *%rax ``` After ```asm mov 0x70(%r14), %rdi - Copy the count from the `zend_array*` pointer mov %rdi, (%rax) - Store the count in the destination's value mov $0x4, 0x8(%rax) - Store IS_LONG(4) in the destination's type ``` And add tracing jit support Closes GH-5584
show more ...
|