[php-src] PR #25496: Optimize repeated user callbacks in array sorting
| From: | drealecs | Date: | Mon, 16 Nov 2026 17:26:27 +0000 |
| Subject: | [php-src] PR #25496: Optimize repeated user callbacks in array sorting | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-40699@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25496
Author: drealecs
This reduces callback-dispatch overhead in
usort(), uasort(),
uksort() and some callback-based diff/intersect functions.
No userland behavior changes are intended.
To achieve this, I added specialized PHP/native call helpers for two by-value arguments. Eligibility
is checked once per comparator.
Paired micro-benchmarks on Apple Silicon/macOS, using matching NTS release builds of master and this
branch, showed the following elapsed-time reductions for 128-entry sorting array:
| Comparator | Reduction |
|---|---:|
| Named PHP function | 13% |
| Static arrow | 14% |
| Instance method | 12% |
| strnatcmp | 12% |
| First-class strnatcmp | 10% |
| strcmp over strings | 23% |