1
0
mirror of https://github.com/php/php-src.git synced 2026-03-31 20:53:00 +02:00
Files
archived-php-src/ext
Tyson Andre d9510342ee 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
2021-02-09 16:09:32 -05:00
..
2021-01-24 16:07:34 +01:00
2021-02-09 15:19:56 +01:00
2021-02-09 14:37:41 +01:00
2021-01-19 10:35:35 +01:00
2021-02-05 14:55:45 +01:00
2021-02-05 13:12:30 +01:00
2021-02-02 16:47:03 +01:00
2021-01-15 12:33:06 +01:00
2021-01-15 12:33:06 +01:00
2021-01-15 12:33:06 +01:00
2021-01-15 12:33:06 +01:00
2021-02-08 19:01:42 +01:00
2021-02-09 12:57:58 +01:00
2021-01-15 12:33:06 +01:00
2021-02-09 22:53:57 +03:00
2021-01-15 12:33:06 +01:00
2020-09-30 21:07:25 +02:00
2020-09-18 14:28:32 +02:00
2021-02-02 16:44:12 +01:00
2021-02-02 10:07:19 +01:00
2021-01-15 12:33:06 +01:00
2021-01-28 23:26:26 +01:00
2021-01-15 12:33:06 +01:00
2021-01-15 12:33:06 +01:00
2021-01-15 12:33:06 +01:00
2021-01-18 15:47:31 +01:00