title: How to speed up template rendering in Symfony2?
body: <p>I have a symfony2 application that renders about 6000 database entities. </p>
  
  <p>I optimized the ORM (propel) queries and the database requests are now very fast. What remains is the symfony controller and the twig template rendering engine.</p>
  
  <p>Is there a way to speed up rendering (e.g. switching to php templates?)
  Can I get more detailed profiling information than from the symfony profiler?</p>
  
  <p>Here's an excerpt from the profiler data.</p>
  
  <p><img src="https://i.stack.imgur.com/NpTg5.png" alt="symfony profiler screenshot"></p>
  
  <p><strong>Edit</strong>: I profiled my code using xDebug and found that generating the objects is very expensive. Creating thousands of PHP objects from database rows in <code>PropelObjectFormater-&gt;getAllObjectsFromRow</code> takes most of the time. </p>
  
  <p><img src="https://i.stack.imgur.com/BTErw.png" alt="profiler_run_excerpt"></p>
  
  <p>The image shows the branch that takes up 95% of the computing time, which is ~2.8 seconds.
  The database retrieval takes ~0.5 seconds, the rendering ~1 second and formatting takes the most time with ~1.5 seconds.</p>
  
  <p>I'm not sure what impact the length of the file containing the PHP class has, but Propel generates <em>a lot</em> of code (my most complex entity base class has almost 10k lines of code) so this might slow down object creation as well.</p>
  
  <p>I think using an array formatter (thus bypassing the object creation step) would be a solution, but that somewhat defeats the purpose of the ORM.</p>