improving-performance.rst 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. Improving Performance
  2. =====================
  3. Bytecode Cache
  4. --------------
  5. It is highly recommended to make use of a bytecode cache like APC.
  6. A bytecode cache removes the need for parsing PHP code on every
  7. request and can greatly improve performance.
  8. "If you care about performance and don't use a bytecode
  9. cache then you don't really care about performance. Please get one
  10. and start using it."
  11. *Stas Malyshev, Core Contributor to PHP and Zend Employee*
  12. Metadata and Query caches
  13. -------------------------
  14. As already mentioned earlier in the chapter about configuring
  15. Doctrine, it is strongly discouraged to use Doctrine without a
  16. Metadata and Query cache (preferably with APC or Memcache as the
  17. cache driver). Operating Doctrine without these caches means
  18. Doctrine will need to load your mapping information on every single
  19. request and has to parse each DQL query on every single request.
  20. This is a waste of resources.
  21. Alternative Query Result Formats
  22. --------------------------------
  23. Make effective use of the available alternative query result
  24. formats like nested array graphs or pure scalar results, especially
  25. in scenarios where data is loaded for read-only purposes.
  26. Read-Only Entities
  27. ------------------
  28. Starting with Doctrine 2.1 you can mark entities as read only (See metadata mapping
  29. references for details). This means that the entity marked as read only is never considered
  30. for updates, which means when you call flush on the EntityManager these entities are skipped
  31. even if properties changed. Read-Only allows to persist new entities of a kind and remove existing
  32. ones, they are just not considered for updates.
  33. Extra-Lazy Collections
  34. ----------------------
  35. If entities hold references to large collections you will get performance and memory problems initializing them.
  36. To solve this issue you can use the EXTRA_LAZY fetch-mode feature for collections. See the :doc:`tutorial <../tutorials/extra-lazy-associations>`
  37. for more information on how this fetch mode works.
  38. Temporarily change fetch mode in DQL
  39. ------------------------------------
  40. See :ref:`Doctrine Query Language chapter <dql-temporarily-change-fetch-mode>`
  41. Apply Best Practices
  42. --------------------
  43. A lot of the points mentioned in the Best Practices chapter will
  44. also positively affect the performance of Doctrine.