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

Prefix global functions #1103

Closed
Toflar opened this issue Sep 25, 2017 · 3 comments
Closed

Prefix global functions #1103

Toflar opened this issue Sep 25, 2017 · 3 comments
Assignees
Labels
Milestone

Comments

@Toflar
Copy link
Member

Toflar commented Sep 25, 2017

We should enable the NativeFunctionInvocationFixer in the php-cs-fixer in the develop branch so all our global functions are prefixed by \. So instead of using e.g. is_object() we should use \is_object(). This will give us quite a performance boost because for global functions, the PHP engine can trigger additional optimizations when using opcode. E.g. if we use \in_array() with true as third parameter and the array is static, it doesn't have to evaluate over and over again but instead opcode will cache the result.
I didn't test it at all but I expect some pretty notable performance gains.

More info: https://veewee.github.io/blog/optimizing-php-performance-by-fq-function-calls/

@leofeyer leofeyer added this to the 4.5.0 milestone Sep 25, 2017
@ausi
Copy link
Member

ausi commented Sep 25, 2017

AFAIK this optimization is only relevant for a subset of native PHP functions, see PHP-CS-Fixer/PHP-CS-Fixer#3048 (comment) and PHP-CS-Fixer/PHP-CS-Fixer#3048 (comment)

IMO we should only activate NativeFunctionInvocationFixer for these methods once the fixer has an option to do so (PHP-CS-Fixer/PHP-CS-Fixer#3048)

@Toflar
Copy link
Member Author

Toflar commented Sep 25, 2017

Yes, I was just about to comment the same. Let's wait for a decision there and use the fixer like we already do now.

@leofeyer
Copy link
Member

I have prefixed our function calls manually with an adjusted version of the fixer in 941b81d. I'll leave the ticket open until the fixer has been adjusted.

I haven't changed the legacy code, although there are a lot of function calls in it as well. How do we handle this?

leofeyer added a commit to contao/installation-bundle that referenced this issue Sep 25, 2017
@leofeyer leofeyer changed the title Use global functions Prefix global functions Sep 28, 2017
leofeyer added a commit to madeyourday/contao-core-bundle that referenced this issue Sep 28, 2017
@leofeyer leofeyer self-assigned this Nov 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants