Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Optimize Arr::first when array is large #15213

Merged
merged 1 commit into from
Sep 1, 2016

Conversation

bepsvpt
Copy link
Contributor

@bepsvpt bepsvpt commented Sep 1, 2016

Variable in PHP uses copy-on-write (http://php.net/manual/en/internals2.variables.intro.php).

Thus, using reset to get the array first element will take additional time.

The side effect is particularly evident when the array is large.

Benchmark: http://sandbox.onlinephpfunctions.com/code/d16f2e69944643bd49ad3b2beb4d37ad23a2d742

@taylorotwell taylorotwell merged commit 647b3ae into laravel:5.3 Sep 1, 2016
@GrahamCampbell GrahamCampbell changed the title Optimize Arr::first when array is large [5.3] Optimize Arr::first when array is large Sep 1, 2016
@vlakoff
Copy link
Contributor

vlakoff commented Sep 9, 2016

I've run some benches, both methods execute at about the same speed on PHP 5.6, however your method seems to be significantly faster on PHP 7.

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.

3 participants