Symfony2 and Twig render performance issues Symfony2 and Twig render performance issues symfony symfony

Symfony2 and Twig render performance issues


I have explained it just 10 hours ago. Long story short: migrate to Twig extensions.


One of my favorite features in symfony is the render tag, embedding controller calls. The profiler adds a lot overhead to every controller calls though, not only speed but uses a lot of memory. You have a few options to speed it up.

The profiler writes every data into a sqlite database by default. IIRC sqlite doesn't allow parallel inserts, so every request have to wait for their turn to access the db to flush data collectors. You can use your development db (mysql or whatever you use) to persist profiler data. A year ago I gained a lot with this in terms of speed.

You can also disable the profiler for sub requests, or only use the profiler when an exception happens. See the framework config reference for the full details.

# config_dev.yamlframework:    profiler:        only_exceptions:      false        only_master_requests: false        dsn:                  sqlite:%kernel.cache_dir%/profiler.db


You can move your controller logic to a service and reference it as twig global variable and then include the template rendered by the controller.

See https://stackoverflow.com/a/13245994/982075 for instructions.