Jonathan Clark
Jonathan Clark

Reputation: 20538

Codeigniter. Autoload models, will things get slower?

I am building an API using Codeigniter. In this API I got 10 models that I use now and then.

Currently I am loading them when I need them but I am thinking of auto loading all models instead (to cut down on space in my controllers).

What will I loose by doing this? Will they cause things to slow down?

Upvotes: 2

Views: 1912

Answers (1)

CuriousMind
CuriousMind

Reputation: 34155

You are instructing CI to auto load your models into memory, which will increase memory footprint. I think autoloading won't have much effect of performance if you have plenty of RAM available but if you run PHP using mod_php then it might cause some slowdown because php processes have to respawned per request.

In any case, before making a decision -- Profile your app! there are two ways to do it.

  1. PECL APD

  2. Xdebug + kcachegrind (linux) or wincachegrind (windows) and it'll show you a few pretty charts that detail the exact timings, counts and memory usage (but you need another extension for that).

I would suggest PECL APD extension because its easier to setup

Upvotes: 2

Related Questions