Repository navigation
Commit c0c6b05
committed
Check a type alias used by several keys once for a missing value type
A type alias referenced by many keys of an array shape is one shared Type object. `MissingTypehintCheck::getIterableTypesWithMissingValueTypehint()` walked that object again for every key referring to it, and for every constant array it met it also ran a second full walk to drop its unsealed part. The array shape that symfony/ux-css generates for its `css()` Twig function has about 840 keys, 126 of them referring to a nested shape, and checking one method parameter against it took seconds.
The callback only depends on the type it's given, so each object is now checked once. Later visits of the same object replay the descriptions added during the first visit, in the same order, so reported errors don't change, duplicates included. The inner walk that drops unsealed parts caches its result per object the same way. Objects are keyed with `spl_object_id()` and kept in the cache for the duration of the walk, so an id can't be reused in between.
| Scenario | Before | After |
|---|---|---|
| New `nested-array-shape-alias.php` bench | 117.4-117.9 ms | 70.4-70.7 ms |
| Real ux-css shape, 2 levels, 1 call, turbo extension loaded | 5.37-5.41 s | 4.41-4.43 s |
The rest of the phpbench suite stays within its existing thresholds. The two scenarios with the largest difference, bug-7140 and bug-8503, were re-run 3 times with 15 iterations each, and the difference turned out to be noise (22.40-22.57 ms vs 22.41-22.49 ms, and 123.9-125.6 ms vs 122.9-127.1 ms).
```
XDEBUG_MODE=off tests/vendor/bin/phpbench run --variant=nested-array-shape-alias.php --iterations=10 --report=aggregate
```1 parent 261a431 commit c0c6b05
2 files changed
Lines changed: 71 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
76 | | - | |
| 77 | + | |
| 78 | + | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
| |||
108 | 110 | | |
109 | 111 | | |
110 | 112 | | |
111 | | - | |
112 | | - | |
113 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
114 | 120 | | |
115 | 121 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
| 122 | + | |
124 | 123 | | |
125 | 124 | | |
126 | 125 | | |
| |||
136 | 135 | | |
137 | 136 | | |
138 | 137 | | |
139 | | - | |
| 138 | + | |
140 | 139 | | |
141 | 140 | | |
142 | 141 | | |
143 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
144 | 173 | | |
145 | 174 | | |
146 | 175 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
0 commit comments