Commit 335c0b3
authored
Optimize SplFixedArray dimension performance (php#18184)
This patch optimizes reading and writing from SplFixedArray with the
dimension operators. It accomplishes this due to the following
optimizations:
* Fast-path for long keys (inlined).
* Optimization hints (UNEXPECTED + assertion)
* Using an unsigned index so we can do a single length comparison
For the following script:
```php
$test = new SplFixedArray(4);
for ($i = 0 ; $i< 5000000; $i++)
$test[1] += $i;
```
On an i7-4790:
```
Benchmark 1: ./sapi/cli/php x.php
Time (mean ± σ): 95.4 ms ± 1.6 ms [User: 91.5 ms, System: 3.2 ms]
Range (min … max): 93.7 ms … 100.8 ms 31 runs
Benchmark 2: ./sapi/cli/php_old x.php
Time (mean ± σ): 119.1 ms ± 1.3 ms [User: 114.7 ms, System: 3.6 ms]
Range (min … max): 117.6 ms … 123.1 ms 24 runs
Summary
./sapi/cli/php x.php ran
1.25 ± 0.03 times faster than ./sapi/cli/php_old x.php
```
On an i7-1185G7:
```
Benchmark 1: ./sapi/cli/php x.php
Time (mean ± σ): 67.9 ms ± 1.1 ms [User: 64.8 ms, System: 3.2 ms]
Range (min … max): 66.6 ms … 72.8 ms 43 runs
Benchmark 2: ./sapi/cli/php_old x.php
Time (mean ± σ): 84.8 ms ± 1.1 ms [User: 81.0 ms, System: 3.9 ms]
Range (min … max): 82.6 ms … 88.0 ms 34 runs
Summary
./sapi/cli/php x.php ran
1.25 ± 0.03 times faster than ./sapi/cli/php_old x.php
```1 parent 6e0b60c commit 335c0b3
1 file changed
+28
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
327 | | - | |
| 327 | + | |
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
334 | | - | |
| 334 | + | |
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
359 | | - | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
360 | 363 | | |
361 | | - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
362 | 372 | | |
| 373 | + | |
| 374 | + | |
363 | 375 | | |
364 | 376 | | |
365 | 377 | | |
366 | 378 | | |
367 | 379 | | |
368 | 380 | | |
369 | 381 | | |
370 | | - | |
371 | | - | |
| 382 | + | |
| 383 | + | |
372 | 384 | | |
373 | 385 | | |
374 | 386 | | |
375 | | - | |
| 387 | + | |
376 | 388 | | |
377 | 389 | | |
378 | 390 | | |
| |||
407 | 419 | | |
408 | 420 | | |
409 | 421 | | |
410 | | - | |
411 | | - | |
412 | 422 | | |
413 | 423 | | |
414 | 424 | | |
415 | 425 | | |
416 | 426 | | |
417 | 427 | | |
418 | | - | |
419 | | - | |
| 428 | + | |
| 429 | + | |
420 | 430 | | |
421 | 431 | | |
422 | 432 | | |
423 | | - | |
| 433 | + | |
424 | 434 | | |
425 | | - | |
426 | 435 | | |
427 | 436 | | |
428 | 437 | | |
| |||
452 | 461 | | |
453 | 462 | | |
454 | 463 | | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
| 464 | + | |
| 465 | + | |
459 | 466 | | |
460 | 467 | | |
461 | 468 | | |
462 | | - | |
| 469 | + | |
463 | 470 | | |
464 | | - | |
465 | 471 | | |
466 | 472 | | |
467 | 473 | | |
| |||
483 | 489 | | |
484 | 490 | | |
485 | 491 | | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
| 492 | + | |
| 493 | + | |
490 | 494 | | |
491 | 495 | | |
492 | 496 | | |
493 | | - | |
| 497 | + | |
494 | 498 | | |
495 | 499 | | |
496 | 500 | | |
| |||
0 commit comments