Do unused use statements decrease performance?

别来无恙 提交于 2019-11-30 01:54:56

问题


I want to know if unused use statements in my class affect performance of my php website?

Does php include all classes in beginning or when need it? If second choice then I think it doesn't affect performance of my system.

For Example: Use statement 'DbConnector' is not used

use model\adapter\DbConnector;

回答1:


No, the use statement does not provoke the the class be loaded (it does not even trigger an autoloader).

It just declares a short name for a class. I assume the cost in terms of CPU and RAM is in the order of a few CPU cycles and a few bytes.




回答2:


Newer versions of PHP, PHP 7 and especially PHP 7.2, is very good at optimising code when it's complied into byte code. I'm pretty sure unsed use statements are just stripped away by the compiler and will not even execute. Therefor it should not have any impact whatsoever. The compiler might use a few more CPU cycles but if you use OPCache there will be no effect on performance.



来源:https://stackoverflow.com/questions/27227616/do-unused-use-statements-decrease-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!