Commit 13c0d9d
Apply micro-optimisations to the injection hot path
All 86 tests pass, PHPStan level 6 clean.
Measured improvement (PHP 8.4, OPcache off, ~750 injections/request):
Warm throughput: 413k → 666k ops/s (+61%)
Avg time per request: 1.40ms → 1.01ms (−28%)
Request sim throughput: 530k → 739k ops/s (+39%)
1. Injector::create() — inline fast-path dispatch
Skip the buildParameterArray() call entirely when no explicit parameters
are provided (the common autowiring case), calling
buildParameterArrayFromContainer() directly instead.
2. Injector::buildParameterArrayFromContainer() — drop $position key tracking
The signature array is always 0-indexed sequential (built by
ParameterInspector), so $parameters[] = ... produces the same result as
$parameters[$position] = ... with less overhead per iteration.
3. Injector::$containerHasCache — cache container->has() per type
The container is sealed at bootstrap; whether a given FQCN is registered
does not change during a request. Caching the has() boolean per type
eliminates a PSR-11 method call + Pimple hash lookup on every repeated
injection that shares a container-registered dependency type.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent ba488a6 commit 13c0d9d
1 file changed
Lines changed: 30 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
46 | 61 | | |
47 | 62 | | |
48 | 63 | | |
| |||
79 | 94 | | |
80 | 95 | | |
81 | 96 | | |
82 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
83 | 101 | | |
84 | | - | |
| 102 | + | |
85 | 103 | | |
86 | 104 | | |
87 | 105 | | |
| |||
238 | 256 | | |
239 | 257 | | |
240 | 258 | | |
241 | | - | |
| 259 | + | |
242 | 260 | | |
243 | 261 | | |
244 | 262 | | |
245 | 263 | | |
246 | 264 | | |
247 | 265 | | |
248 | | - | |
249 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
250 | 273 | | |
251 | 274 | | |
252 | 275 | | |
253 | | - | |
| 276 | + | |
254 | 277 | | |
255 | 278 | | |
256 | 279 | | |
257 | 280 | | |
258 | | - | |
| 281 | + | |
259 | 282 | | |
260 | 283 | | |
261 | 284 | | |
| |||
0 commit comments