Commit a3576bd
authored
zend_compile: Optimize
* zend_compile: Optimize `array_map()` with callable convert callback into foreach
For:
<?php
function plus1($x) {
return $x + 1;
}
$array = array_fill(0, 100, 1);
$count = 0;
for ($i = 0; $i < 100_000; $i++) {
$count += count(array_map(plus1(...), $array));
}
var_dump($count);
This is ~1.1× faster:
Benchmark 1: /tmp/test/before -d opcache.enable_cli=1 /tmp/test/test6.php
Time (mean ± σ): 172.2 ms ± 0.5 ms [User: 167.8 ms, System: 4.2 ms]
Range (min … max): 171.6 ms … 173.1 ms 17 runs
Benchmark 2: /tmp/test/after -d opcache.enable_cli=1 /tmp/test/test6.php
Time (mean ± σ): 155.1 ms ± 1.3 ms [User: 150.6 ms, System: 4.2 ms]
Range (min … max): 154.2 ms … 159.3 ms 18 runs
Summary
/tmp/test/after -d opcache.enable_cli=1 /tmp/test/test6.php ran
1.11 ± 0.01 times faster than /tmp/test/before -d opcache.enable_cli=1 /tmp/test/test6.php
With JIT it becomes ~1.7× faster:
Benchmark 1: /tmp/test/before -d opcache.enable_cli=1 -d opcache.jit=tracing /tmp/test/test6.php
Time (mean ± σ): 166.9 ms ± 0.6 ms [User: 162.7 ms, System: 4.1 ms]
Range (min … max): 166.1 ms … 167.9 ms 17 runs
Benchmark 2: /tmp/test/after -d opcache.enable_cli=1 -d opcache.jit=tracing /tmp/test/test6.php
Time (mean ± σ): 94.5 ms ± 2.7 ms [User: 90.4 ms, System: 3.9 ms]
Range (min … max): 92.5 ms … 103.1 ms 31 runs
Summary
/tmp/test/after -d opcache.enable_cli=1 -d opcache.jit=tracing /tmp/test/test6.php ran
1.77 ± 0.05 times faster than /tmp/test/before -d opcache.enable_cli=1 -d opcache.jit=tracing /tmp/test/test6.php
* zend_compile: Skip `assert(...)` callbacks for array_map() optimization
* zend_compile: Remove `zend_eval_const_expr()` in array_map optimization
* zend_vm_def: Check simple types without loading the arginfo in ZEND_TYPE_ASSERT
* zend_vm_def: Handle references for ZEND_TYPE_ASSERT
* zend_compile: Fix handling of constant arrays for `array_map()`
* zend_compile: Fix leak of unused result in array_map() optimization
* zend_compile: Support static methods for `array_map()` optimization
* UPGRADINGarray_map() with callable convert callback into foreach (#20934)1 parent e9e0fe4 commit a3576bd
File tree
14 files changed
+1163
-573
lines changed- Zend
- tests
- functions
- ext/standard/tests/array
14 files changed
+1163
-573
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
154 | 159 | | |
155 | 160 | | |
156 | 161 | | |
| |||
Lines changed: 2 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
| 22 | + | |
| 23 | + | |
25 | 24 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
| 21 | + | |
| 22 | + | |
24 | 23 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5027 | 5027 | | |
5028 | 5028 | | |
5029 | 5029 | | |
5030 | | - | |
| 5030 | + | |
| 5031 | + | |
| 5032 | + | |
| 5033 | + | |
| 5034 | + | |
| 5035 | + | |
| 5036 | + | |
| 5037 | + | |
| 5038 | + | |
| 5039 | + | |
| 5040 | + | |
| 5041 | + | |
| 5042 | + | |
| 5043 | + | |
| 5044 | + | |
| 5045 | + | |
| 5046 | + | |
| 5047 | + | |
| 5048 | + | |
| 5049 | + | |
| 5050 | + | |
| 5051 | + | |
| 5052 | + | |
| 5053 | + | |
| 5054 | + | |
| 5055 | + | |
| 5056 | + | |
| 5057 | + | |
| 5058 | + | |
| 5059 | + | |
| 5060 | + | |
| 5061 | + | |
| 5062 | + | |
| 5063 | + | |
| 5064 | + | |
| 5065 | + | |
| 5066 | + | |
| 5067 | + | |
| 5068 | + | |
| 5069 | + | |
| 5070 | + | |
| 5071 | + | |
| 5072 | + | |
| 5073 | + | |
| 5074 | + | |
| 5075 | + | |
| 5076 | + | |
| 5077 | + | |
| 5078 | + | |
| 5079 | + | |
| 5080 | + | |
| 5081 | + | |
| 5082 | + | |
| 5083 | + | |
| 5084 | + | |
| 5085 | + | |
| 5086 | + | |
| 5087 | + | |
| 5088 | + | |
| 5089 | + | |
| 5090 | + | |
| 5091 | + | |
| 5092 | + | |
| 5093 | + | |
| 5094 | + | |
| 5095 | + | |
| 5096 | + | |
| 5097 | + | |
| 5098 | + | |
| 5099 | + | |
| 5100 | + | |
| 5101 | + | |
| 5102 | + | |
| 5103 | + | |
| 5104 | + | |
| 5105 | + | |
| 5106 | + | |
| 5107 | + | |
| 5108 | + | |
| 5109 | + | |
| 5110 | + | |
| 5111 | + | |
| 5112 | + | |
| 5113 | + | |
| 5114 | + | |
| 5115 | + | |
| 5116 | + | |
| 5117 | + | |
| 5118 | + | |
| 5119 | + | |
| 5120 | + | |
| 5121 | + | |
| 5122 | + | |
| 5123 | + | |
| 5124 | + | |
| 5125 | + | |
| 5126 | + | |
| 5127 | + | |
| 5128 | + | |
| 5129 | + | |
| 5130 | + | |
| 5131 | + | |
| 5132 | + | |
| 5133 | + | |
| 5134 | + | |
| 5135 | + | |
| 5136 | + | |
| 5137 | + | |
| 5138 | + | |
5031 | 5139 | | |
5032 | 5140 | | |
5033 | 5141 | | |
| |||
5099 | 5207 | | |
5100 | 5208 | | |
5101 | 5209 | | |
| 5210 | + | |
| 5211 | + | |
5102 | 5212 | | |
5103 | 5213 | | |
5104 | 5214 | | |
5105 | 5215 | | |
5106 | 5216 | | |
5107 | | - | |
| 5217 | + | |
5108 | 5218 | | |
5109 | 5219 | | |
5110 | 5220 | | |
| |||
5120 | 5230 | | |
5121 | 5231 | | |
5122 | 5232 | | |
5123 | | - | |
| 5233 | + | |
5124 | 5234 | | |
5125 | 5235 | | |
5126 | 5236 | | |
| |||
5263 | 5373 | | |
5264 | 5374 | | |
5265 | 5375 | | |
5266 | | - | |
| 5376 | + | |
5267 | 5377 | | |
5268 | 5378 | | |
5269 | 5379 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8846 | 8846 | | |
8847 | 8847 | | |
8848 | 8848 | | |
| 8849 | + | |
| 8850 | + | |
| 8851 | + | |
| 8852 | + | |
| 8853 | + | |
| 8854 | + | |
| 8855 | + | |
| 8856 | + | |
| 8857 | + | |
| 8858 | + | |
| 8859 | + | |
| 8860 | + | |
| 8861 | + | |
| 8862 | + | |
| 8863 | + | |
| 8864 | + | |
| 8865 | + | |
| 8866 | + | |
| 8867 | + | |
| 8868 | + | |
| 8869 | + | |
| 8870 | + | |
| 8871 | + | |
| 8872 | + | |
| 8873 | + | |
| 8874 | + | |
| 8875 | + | |
| 8876 | + | |
| 8877 | + | |
| 8878 | + | |
| 8879 | + | |
| 8880 | + | |
8849 | 8881 | | |
8850 | 8882 | | |
8851 | 8883 | | |
| |||
0 commit comments