Commit df486fd
committed
Optimize SplFixedArray dimension performance
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 5dd9b0d commit df486fd
1 file changed
+25
-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 | 360 | | |
361 | | - | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
362 | 369 | | |
| 370 | + | |
| 371 | + | |
363 | 372 | | |
364 | 373 | | |
365 | 374 | | |
366 | 375 | | |
367 | 376 | | |
368 | 377 | | |
369 | 378 | | |
370 | | - | |
371 | | - | |
| 379 | + | |
| 380 | + | |
372 | 381 | | |
373 | 382 | | |
374 | 383 | | |
375 | | - | |
| 384 | + | |
376 | 385 | | |
377 | 386 | | |
378 | 387 | | |
| |||
407 | 416 | | |
408 | 417 | | |
409 | 418 | | |
410 | | - | |
411 | | - | |
412 | 419 | | |
413 | 420 | | |
414 | 421 | | |
415 | 422 | | |
416 | 423 | | |
417 | 424 | | |
418 | | - | |
419 | | - | |
| 425 | + | |
| 426 | + | |
420 | 427 | | |
421 | 428 | | |
422 | 429 | | |
423 | | - | |
| 430 | + | |
424 | 431 | | |
425 | | - | |
426 | 432 | | |
427 | 433 | | |
428 | 434 | | |
| |||
452 | 458 | | |
453 | 459 | | |
454 | 460 | | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
| 461 | + | |
| 462 | + | |
459 | 463 | | |
460 | 464 | | |
461 | 465 | | |
462 | | - | |
| 466 | + | |
463 | 467 | | |
464 | | - | |
465 | 468 | | |
466 | 469 | | |
467 | 470 | | |
| |||
483 | 486 | | |
484 | 487 | | |
485 | 488 | | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
| 489 | + | |
| 490 | + | |
490 | 491 | | |
491 | 492 | | |
492 | 493 | | |
493 | | - | |
| 494 | + | |
494 | 495 | | |
495 | 496 | | |
496 | 497 | | |
| |||
0 commit comments