Anybody got any performance tips for Symfony2 like “use _”, “disable _” etc? Things like cache and such, but less obvious things like using Doctrine2 query cache.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Couple of (fairly basic) things from the Doctrine Docs
Use array hydration for read only actions
There is an extra overhead (memory, loading proxies and the like) associated with hydrating objects.
If you are just displaying lists of items, or lists of entity properties for a single items (for example a product page, a list of recent blog articles, or most front end operations!) you can use
$query->getResult(Query::HYDRATE_ARRAY);This approach can also prevent any accidental lazy-loading problems that may arise from the next point (due to the lack of proxies!)
Beware of lazy loading when using entities with associations
It can be tempting to over use some of Doctrine’s in-built repository methods
$repo->findAll(), or to not explicitly define associations in your DQL (via joins) (for brevity/speed/whatever excuse!).Should a query return an array of (say Article) objects, that you then loop over in your view to display each article, and each article has a collection of comments. If you do not define an Eager load, or explicitly join the comment entity in the DQL, Doctrine will lazy load in the comment entities as requested (which is very useful in some cases). This means an extra SQL query per lazy load.
If you were displaying a list of 10 articles, that would result in 1 query to get the article list, and an additional 10 queries to lazy load each comment association (when one one query is all that is needed!)
By default Doctrine will fetch all all the properties for a given entity.
This isn’t ideal on high traffic pages (equivalent to doing a
SELECT *?). Especially if you are only using 1 or 2 properties for a given entity.Rather than
You could do
You can use Symfony’s profiler to keep an eye on how many queries are being generated by Doctrine.