[php-src] PR #25389: ext/standard: Add a fast path for sort() and rsort() on packed int ar…

From: Date: Wed, 11 Nov 2026 14:57:22 +0000
Subject: [php-src] PR #25389: ext/standard: Add a fast path for sort() and rsort() on packed int ar…
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-40539@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/25389 Author: adamcable …rays With the default SORT_REGULAR flag, a packed array whose elements are all integers is now sorted as a plain zend_long buffer, instead of being converted to a hash, sorted as Buckets through comparison and swap callbacks, and converted back. The result is identical: comparing two integers cannot call user code, emit a diagnostic or throw, and since the keys are renumbered, the order of equal integers is unobservable. Holes are squeezed out and the next free key and internal pointer are reset, as the generic path does. Any other array, including one holding a reference, takes the existing path. Runs of 2 to 5 elements are sorted with the branchless sorting networks AlphaDev found for libc++ (Mankowitz et al., Nature 618, 2023), which std::sort uses for arithmetic types. They are only correct for a strict weak ordering, which integer comparison is, so they are not reachable from user comparators. sort() and rsort() on lists of integers become 2-4x faster; other arrays are unaffected.

« previous php.git-pulls (#40539) next »