views:

219

answers:

2

I'm lazy loading my Doctrine classes in my website. Benchmarking has showed that Doctrine::loadModels('models') takes over 100 ms to complete! I have 118 tables in total, but still...

setting attribute to conservative loading:

Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);

running the benchmark part:

$CI->benchmark->mark('Doctrineload_start');
Doctrine::loadModels(APPPATH.'models');
$CI->benchmark->mark('Doctrineload_end');

And the result:

Doctrineload    0.1085 (seconds)

Is this 'normal'?

'context':

Loading Time Base Classes   0.0233
Doctrineinit    0.0435  //doctrine_pi.php file, doctrine configuration + db account
Doctrineload    0.1085
Masterpageset   0.0001
Userload    0.1208 //1 db query
Masterpageaddcontent    0.1565 //1 db query, loading view with some <?=?> php parsing
Masterpageshow      0.0203 //loading view
Controller Execution Time ( Home / Index )      0.3591
Total Execution Time    0.3826
+2  A: 

Are you using an opcode caching system like APC or xcache? If not, you should consider installing one. You'll see a dramatic improvement when using larger frameworks and libraries like Doctrine. PHP spends a non-trivial amount of time upon each request re-compiling all of the files needed to generate the response. Using an opcode cache will reduce this overhead considerably.

APC is slated to be included within PHP eventually, one if its maintainers is Rasmus Lerdorf himself, and it seems to be a very popular system. See: http://pecl.php.net/package/APC

XCache was written by the creator of lighttpd and it seems to be a pretty viable option, though I haven't used it in a while. See: http://xcache.lighttpd.net/

awgy
No, we aren't using one yet. I know Doctrine has a built-in compile function. I'm gonna try that. Thanks!
Ropstah
As a followup: Did you already install a caching system? If so, did you experienced any improvement?
Sebastián Grignoli
A: 

Bear in mind, Doctrine compilation is just giving you a more compact version of the original php files that will reduce the time it takes for PHP interpreter to parse the source code. It does not translate to bytecode. So a bytecode cache is still going to add a lot of value.

webgr