Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will reducing number of includes/requires increase performance?

What is better practice for script performance tuning?

This one?

require_once("db.php");

if (!is_cached()) {
  require_once("somefile.php");
  require_once("somefile2.php");
  //do something
} else {
  //display something
}

Or this one?

require_once("db.php");
require_once("somefile.php");
require_once("somefile2.php");

if (!is_cached()) {
  //do something
} else {
  //display something
}

Is it worth placing includes/requires into flow control structures or no?

Thank you

like image 871
Kirzilla Avatar asked Aug 06 '10 12:08

Kirzilla


People also ask

Is the reduction of features beneficial to improving performance?

Feature reduction leads to the need for fewer resources to complete computations or tasks. Less computation time and less storage capacity needed means the computer can do more work. During machine learning, feature reduction removes multicollinearity resulting in improvement of the machine learning model in use.

How can models improve performance?

Like humans, the more training algorithms get, the likelihood of better performance increases. One way to improve model performance is to provide more training data samples to the algorithms. The more data it learns from, the more cases it is able to correctly identify.


1 Answers

Yes, it will increase performance and contrary to what others said, the impact may not be negligible.

When you include/require files, PHP will check all the defined include_paths until it finds the file or there is nothing more to check. Depending on the amount of include pathes and the amount of files to include, this will have a serious impact on your application, especially when including each and every file up front. Lazy including (like in your first example) or - even better - using the Autoloader is advisable.

Related reading that addresses this in more details:

  • Zend Framework Performance Guide*

*The advice given there is applicable to any application or framework

like image 82
Gordon Avatar answered Oct 03 '22 20:10

Gordon