Repository navigation
Conversation
In SORT_STRING mode, array_unique() converted every integer element to a temporary string before inserting it into the table of seen values. Insert integers directly as integer keys. When the first integer arrives, add an integer alias for each canonical numeric string key already seen, and look up later numeric strings by their integer value, so integers, numeric strings, floats and references still compare by their string form. Arrays of strings only pay one extra branch per element. Neoverse-N1, GCC 13.3 -O2 NTS, 200,000 elements: sparse integers 1.91x, dense integers 6.22x, alternating integers and numeric strings 2.11x, strings only +0.3% (+0.7% instructions).
iliaal
force-pushed
the
opt/array-unique-sort-string-int
branch
from
November 27, 2026 16:46
a2bec53 to
cb739d2
Compare
Owner
Author
|
Submitted upstream as php/php-src phpGH-25845: php#25845 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In SORT_STRING mode, array_unique() converts every integer element to a temporary zend_string via zval_get_tmp_string() before inserting it into the seen HashTable.
Insert IS_LONG elements directly as integer keys in seen and lazily add integer aliases for any previously seen canonical numeric string keys when the first integer is encountered, keeping pure-string arrays free of ZEND_HANDLE_NUMERIC checks while preserving SORT_STRING equivalence between ints, numeric strings, floats, and references.
On ARM64 (Neoverse-N1, GCC 13.3 -O2 NTS): sparse 64-bit ints 5.33x (-81.30%), dense ints 4.43x (-77.44%), mixed arrays 1.23x (-18.90%), pure-string control +1.00% (+0.87% insns).