Skip to content

Small optimizations to array_chunk #19190

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

Merged
merged 2 commits into from
Jul 21, 2025
Merged

Conversation

nielsdos
Copy link
Member

See individual commits.

nielsdos added 2 commits July 20, 2025 16:43
For this benchmark:
```php
$length = 25;
for ($i=0;$i<1000;$i++)
  array_chunk(range(0, 10000), $length);
```

On an i7-4790, length=25 speeds up by 1.8x and length=1 by 1.27x.
On an i7-1185G7, length=25 speeds up by 1.08x and length=1 by 1.02x.
By preallocating it as a packed array, we save the initial
initialization overhead.
Gives a few extra percentage points improvement.
@nielsdos nielsdos merged commit 1b169bf into php:master Jul 21, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy