CakePhp speed optimization

cakephp, cakephp-2.0

Solution

`public $uses()` does not matter. you can add as many as you want. Cake will only lazyload them if needed somewhere. Just make sure you got `recursive = -1` per default in your AppModel and only raise it or contain data you really need.

But your components will all be loaded and initialized right away. You might want to reduce those.

Those two attributes cannot be your bottleneck, though. You must have some other serious issues.

Also don't make assumptions in debug mode. The real speed is measured/obseved with debug 0 where no additional debug info is gathered and the cache is not constantly replaced.

EDIT: Please note that my words above are only meant from a "speed point of view". It does not matter for speed. But it is not recommended to add models in $uses if you are able to reach those via relations and the relation chain.

So let's say you want to make a dashbard. In most cases you only need to add "User" model, since Profile, Images, and other models are usually directly accessable via `$this->User->Profile->foo($bar)` etc.

Problem

My app is working very slow. I am using Cakephp 2.3.1 version. Will it be beneficial to load Model, Components and Helpers in the functions where they are needed? Right now I am calling them in class. eg: ``` class PanelsController extends AppController { public $name = 'Panel'; public $uses = array(list of models goes here); public $components = array(list of components goes here); ................. } ``` What other techniques do you suggest. Thanks

Original source