Micro Optimization
Closed this issue · 2 comments
Use imports for standard php functionality since it seems that they are slightly faster that way.
See https://www.deviaene.eu/articles/2023/why-prefix-php-functions-calls-with-backslash/
You should use the PHP-CS-Fixer to do this automatically (for all of Pimcore).
I propose the following config (that's also how Symfony does it):
'native_function_invocation' => [
'include' => [
'@compiler_optimized',
],
'scope' => 'namespaced',
'strict' => true,
],
This will automatically fix all functions that are worth it. The functions in @compiler_optimized
are specifically optimized in the Zend engine/Opcache, but only if the compiler can be sure the these are the global functions (so without the leading backslash/import they are not optimized)!
Any other function is not worth it in my eyes, it's just noise in the code with all those extra backslashes/imports. Yes, it is a tiny bit faster, but not really measurable and only on the very first function call, because after that Opcache remembers if it's a global function or not. So it may make a difference if you don't have Opcache enabled, but in that case everything is slow anyway, and it doesn't matter.
P.S. there's also native_constant_invocation
which could be enabled to speed up constant resolving.