Well, optimizing and hacking Doctrine 2 will not be an easy task. I can only advise you to follow the official "best practice":
- Use Query Cache
- Use Metadata Cache
- Pre-generate proxies
- Avoid listeners (or merge them by event type (flush, update), it will avoid the lookup time and the loop for subscribed events)
- Use lazy-loading whenever it is possible
- Make sure your relationships or inheritance are not messed up
(Note that I didn't mentioned Result cache which should not be a way to optimize an application)
From my use, the most important part I had to optimize was not Doctrine itself (while there are optimizations to do to the core) but the generated Query, as always, I EXPLAIN
ed the queries and optimized indexes.
Doctrine 2 can be high memory consuming so loading a lot of entities at once may slow down your application, you may find it useful to known about clear()
, detach()
, iterate()
methods.
Despite the fact Doctrine 2 can sometimes be slow, I mostly noticed that I was able to optimize application somewhere else, within the Zend Framework or PHP themselves.
Let's say, Doctrine 2 takes 100ms where Zend Framework takes 300ms for a total of 450ms (I/O stuffs, PHP internal functions, etc..)
If you can divide easily by two the time taken by Zend Framework, optimizing Doctrine 2 to gain like 10% will not increase notably the speed of your application. Think about it twice.
Here are a few tips:
- Create your own view instead of using View Helpers (avoid the helper lookup)
- Cache your Zend_Config object (really heavy load)
- Avoid Regex routes whenever possible (ZF routes are a big bottleneck)
- Use a ClassMap autoloader instead of the native Zend_Loader_Autoloader
There are tons of optimization to do, some have a real impact while others don't.
Make sure to find them by profiling your application, an easy and cross-platform is to use webgrind.