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

Enforce import of global functions or using FQN calls #462

Open
ilnytskyi opened this issue Aug 8, 2023 · 1 comment
Open

Enforce import of global functions or using FQN calls #462

ilnytskyi opened this issue Aug 8, 2023 · 1 comment

Comments

@ilnytskyi
Copy link

Rule

Reason

I used code example from here
https://tideways.com/profiler/blog/compiler-optimized-php-functions
https://veewee.github.io/blog/optimizing-php-performance-by-fq-function-calls/

If we import or use FQN call for the global function php produces more optimized code.
Also visible via profilers:
SPX:
Selection_578

Same effect with blackfire:

  1. Without import
    Selection_575

  2. with import
    Selection_576

Although the optimization might not be that significant for whole codebase it also helps to specify dependency via use statement.
It also might improve performance of some loops when checks like is_array, ltrim, preg_match etc. are used as PHP would no more execute extra opcode INIT_NS_FCALL_BY_NAME

Also by import or FQN core function for setup:di:compile code we might reduce magento compilation time by a few seconds.

Selection_577

Implementation

Can be taken from here: https://github.com/slevomat/coding-standard/blob/master/doc/namespaces.md#slevomatcodingstandardnamespacesreferenceusednamesonly-

    <rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
        <properties>
            <property name="allowFallbackGlobalFunctions" value="0" />
            <property name="allowFallbackGlobalConstants" value="0" />
        </properties>
    </rule>
@ilnytskyi ilnytskyi added the proposal New rule proposal label Aug 8, 2023
@m2-assistant
Copy link

m2-assistant bot commented Aug 8, 2023

Hi @ilnytskyi. Thank you for your report.
To speed up processing of this issue, make sure that you provided sufficient information.
Add a comment to assign the issue: @magento I am working on this


Join Magento Community Engineering Slack and ask your questions in #github channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant