Skip to content

Avoid copying arrays when checking their type - #135

Merged
GrahamCampbell merged 1 commit into
2.10from
avoid-array-copy-in-type-checks
Nov 17, 2026
Merged

GrahamCampbell merged 1 commit into
2.10from
avoid-array-copy-in-type-checks

Conversation

@GrahamCampbell

@GrahamCampbell GrahamCampbell commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Utils::type() called reset() on its by-value argument, which makes PHP copy the whole array first, and Utils::isArray() and Utils::isObject() built the complete list of keys in order to look at the first one. Every validated function argument, every element compared by max_by() and min_by(), and every index and slice therefore cost time and memory in proportion to the size of the array, so length(@) on an object with a million members took several milliseconds and about 40 MB. All three now stop at the first key without copying the array or listing its keys, and classify every value exactly as before. There is no change in behaviour, and this is intended for 2.10.0.

@GrahamCampbell
GrahamCampbell force-pushed the avoid-array-copy-in-type-checks branch from a9870d9 to 83468d6 Compare November 17, 2026 00:17
@GrahamCampbell
GrahamCampbell force-pushed the avoid-array-copy-in-type-checks branch from 83468d6 to 1c3e72e Compare November 17, 2026 01:38
@GrahamCampbell
GrahamCampbell merged commit e86a383 into 2.10 Nov 17, 2026
40 checks passed
@GrahamCampbell
GrahamCampbell deleted the avoid-array-copy-in-type-checks branch November 17, 2026 15:08
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.

1 participant