Skip to content

Add hyperfine benchmarks for individual improvements based on UPGRADING and NEWS - #1

Merged
beberlei merged 2 commits into
mainfrom
8.6-snippet-benchmarks
Nov 16, 2026
Merged

beberlei merged 2 commits into
mainfrom
8.6-snippet-benchmarks

Conversation

@beberlei

@beberlei beberlei commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Farmed UGPRADING and NEWS for performance immprovements, generated benchmarks for hyperfine for each example, and a script around them. Results on our last Hetzner run:

Benchmark PHP 8.5 PHP 8.6 % Change Summary
str_repeat_one 1836.1 ms ± 9.2 36.7 ms ± 13.1 −98.0% str_repeat($s, 1) returns the input string without copying (#23681)
str_pad 3890.8 ms ± 49.1 98.3 ms ± 14.7 −97.5% Padding is filled with memset for one character and by doubling copies for longer pad strings (#19272, #23661)
array_reduce 736.2 ms ± 14.2 26.6 ms ± 8.7 −96.4% The array accumulator is no longer copied on each callback call, so the $carry[] = …; return $carry; pattern goes from O(n²) to O(n) (#21340)
collator_sort_with_sort_keys 2695.1 ms ± 13.2 139.1 ms ± 15.0 −94.8% Collator::sortWithSortKeys() sizes its buffers to the array instead of allocating 2 × 1 MiB per call (#23504)
array_intersect 1139.4 ms ± 15.5 61.7 ms ± 11.4 −94.6% Hash-based matching instead of sorting all arrays (#23019)
zip_add_from_string 266.4 ms ± 6.1 38.0 ms ± 1.1 −85.7% ZipArchive::addFromString() no longer copies the content (#20497)
mb_str_pad 634.3 ms ± 14.1 113.2 ms ± 7.4 −82.2% mb_str_pad() pads by doubling copies (#23667)
addcslashes 414.1 ms ± 13.1 85.5 ms ± 8.7 −79.4% Octal escapes are generated without a formatted print (#23680)
printf 1484.5 ms ± 31.9 540.3 ms ± 15.2 −63.6% printf() with only %s/%d is compiled into string interpolation (#19658); this only applies inside functions
array_sum_product 819.4 ms ± 50.8 356.7 ms ± 11.6 −56.5% Integer-only fast path for array_sum() / array_product() (#21787)
first_class_callable 1637.5 ms ± 41.9 833.2 ms ± 19.0 −49.1% First-class callables like foo(...) are cached instead of allocated each time (#19863)
array_unshift 776.6 ms ± 25.2 399.2 ms ± 14.0 −48.6% Fast path for packed (list) arrays (#20353)
closure_static 880.9 ms ± 15.4 487.2 ms ± 13.3 −44.7% Stateless closure cache for static fn closures without captures (RFC); this only applies inside functions
pathinfo 1028.3 ms ± 13.0 644.7 ms ± 16.2 −37.3% pathinfo() with a single PATHINFO_* flag skips the components that weren't requested (#23726)
sort_single_element 982.1 ms ± 47.5 636.4 ms ± 7.6 −35.2% Sorting a single-element array skips unpacking and the comparator (#23550)
asymmetric_visibility 462.1 ms ± 19.3 310.1 ms ± 4.1 −32.9% The private(set) / protected(set) check is cached for writes (#22709)
preg_replace_callback 514.1 ms ± 13.8 416.2 ms ± 15.3 −19.0% Modifying $matches in the callback no longer copies the array (#21340)
intval_binary 857.3 ms ± 17.2 720.1 ms ± 18.1 −16.0% intval('0b…', 2) no longer copies the string to strip the prefix (0af87e970)
dom_split_text 321.1 ms ± 13.1 271.0 ms ± 13.3 −15.6% DOMText::splitText() is faster and uses less memory (#20371)
array_fill_keys 614.2 ms ± 53.2 537.3 ms ± 42.2 −12.5% array_fill_keys() optimized (#20347)
new_known_constructor 475.0 ms ± 14.0 432.9 ms ± 12.8 −8.9% Faster argument passing to constructors known at compile time, e.g. new self(...) (#20259)
uri_rfc3986_getters 435.2 ms ± 7.4 405.8 ms ± 10.4 −6.8% Getters on already-normalized Uri\Rfc3986\Uri objects no longer re-normalize (#21726)
array_column 446.4 ms ± 9.5 418.7 ms ± 9.3 −6.2% Key normalization moved out of the main loop (#23786)
array_map_fcc 422.6 ms ± 21.3 412.0 ms ± 17.0 −2.5% array_map(foo(...), $a) is compiled into a foreach loop (#20934)
array_map_multiple 589.7 ms ± 21.5 578.2 ms ± 2.8 −1.9% array_map() with several arrays avoids allocations on each iteration (79adb01bf)
array_walk 740.8 ms ± 9.8 729.8 ms ± 10.7 −1.5% Less callback overhead per element (#20322)
vm_stack_recursion 375.2 ms ± 13.7 378.5 ms ± 12.8 +0.9% VM stack page cache for deep recursion on a fragmented heap (#23470); the snippet doesn't trigger the slow path
json_decode 2313.4 ms ± 29.4 2345.2 ms ± 115.9 +1.4% Regression check: the new JSON error locations add no cost to successful decodes (#22487)
stream_copy_to_socket 847.9 ms ± 45.1 867.3 ms ± 48.8 +2.3% stream_copy_to_stream() from file to socket uses sendfile() (#20399); no difference in this run
array_map_fcc_strict 424.7 ms ± 15.5 440.3 ms ± 9.2 +3.7% Control: the array_map() → foreach rewrite is disabled under strict_types=1 (#23889)
json_encode 858.6 ms ± 13.2 907.5 ms ± 12.7 +5.7% Faster encoding of arrays/objects and JSON_PRETTY_PRINT indentation (#21474); no gain measured
str_split ⚠️ 24.4 ms ± 2.4 27.2 ms ± 1.3 invalid str_split() is optimized, especially for length 1 (#20419); this run used the old snippet, which OPcache evaluates at compile time

What stands out:

  • Big wins match the upstream PRs: array_reduce, array_intersect, str_pad and str_repeat($s, 1) all show the large speedups the PRs claimed. Zip and Collator also improved much more than I expected.
  • Several gains are much smaller than the PRs claim:
    • closure_static: 1.06× here, against about 80% faster in the PR.
    • array_map_fcc: 1.16× here, against 1.11× without JIT and 1.77× with the tracing JIT in the PR. A run with JIT=tracing would test that claim.
    • sort_single_element: the 8.5 times were very noisy (±184 ms). In the earlier pre-flight it was 631 → 404 ms.
  • The strict_types control works: array_map_fcc_strict shows no gain, which confirms the rewrite is off under strict_types=1.
  • Three results went the wrong way:
    • stream_copy_to_socket (0.82×): the new sendfile path is slower here, though the PR says file-to-socket gains the most. That could be specific to Docker or arm64, so it needs re-running on the bench machine before anything goes in the post.
    • json_encode (0.93×): the spread is large, so this may be noise, but 8.6 was supposed to be faster.
    • vm_stack_recursion (0.96×): no improvement. The heap is probably not fragmented enough to trigger the slow path in this VM. The snippet may need more memory pressure on the real machine.
  • json_decode is neutral: the error-location feature added no measurable cost on successful decodes.

For blog numbers, run it on the php-benchmarks machine, pinned to one CPU with turbo boost off.

@beberlei
beberlei merged commit a3a4585 into main Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants