Skip to content

optimize in_array calls #61107

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 1 commit into from
Jul 15, 2025
Merged

Conversation

gharlan
Copy link
Contributor

@gharlan gharlan commented Jul 12, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? no
Deprecations? no
Issues
License MIT

in_array calls are optimized by php when fully-qualified and using a static array and the strict param:

namespace Foo;

$a = [1, 2, 3];
\in_array($b, $a, true); // not optimized because variable array

\in_array($b, [1, 2, 3]); // not optimized because missing strict param

in_array($b, [1, 2, 3], true); // not optimized because no leading `\` or import

\in_array($b, [1, 2, 3], true); // optimized

https://3v4l.org/FjKJ0/vld
You can see in the "VLD" tab that lines 6, 8 and 10 use the function call opcodes (INIT_FCALL or INIT_NS_FCALL_BY_NAME) while line 12 uses the optimized IN_ARRAY opcode without a function call.

In this pull request I changed only those places where the change enables the optimized opcode (by adding the strict param or inlining the array).

@xabbuh
Copy link
Member

xabbuh commented Jul 13, 2025

As this is not a bugfix the PR should target the 7.4.

@OskarStark OskarStark modified the milestones: 6.4, 7.4 Jul 13, 2025
@gharlan gharlan changed the base branch from 6.4 to 7.4 July 14, 2025 12:35
@gharlan gharlan force-pushed the optimize-inarray branch 2 times, most recently from 962da8d to 925a49f Compare July 14, 2025 12:45
@gharlan
Copy link
Contributor Author

gharlan commented Jul 14, 2025

Rebased and updated for target 7.4.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me with minor CS changes. Thanks.

@nicolas-grekas
Copy link
Member

Thank you @gharlan.

@nicolas-grekas nicolas-grekas merged commit f4ca886 into symfony:7.4 Jul 15, 2025
2 of 3 checks passed
@gharlan gharlan deleted the optimize-inarray branch July 15, 2025 09:43
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.

5 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