Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages showcasing Symfony with Docker, APIs, queues & async tasks, Webpack, SPAs, etc.

New in Symfony 2.7: Twig Profiler

Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.

Contributed by
Fabien Potencier
in #13428.

In Symfony project we believe that all the information relevant to developers should be one click away. That's why in Symfony 2.7 we've added a new panel with Twig information in the web debug toolbar.

Currently, the information about the resources used to render each template is displayed in the Timeline panel of the Symfony profiler:

Twig Basic Profiler

Sadly, this panel doesn't provide much detail for templates. Moreover, some templates aren't registered, so their information is missing in that panel.

Symfony 2.7 solves these problems thanks to the new profiler introduced by Twig in its 1.18.0 version. First, you'll see a new Twig debug panel in the web debug toolbar that gives you a quick overview of the main Twig stats:

Twig Debug Panel

If you click on that panel, you'll see the full information collected by the Twig profiler. First, you'll get the main Twig stats for the page, which is the first thing to check when things go wrong:

Twig Profiler Stats

Second, you'll see the full list of templates used to render the page, including the templates of third-party bundles and the template fragments:

Twig Profiler Templates

Lastly, you'll get the full call graph executed by Twig to render the page. This information is mostly useful when things go wrong or your templates render slowly. Thanks to the detailed information, you'll discover the performance bottlenecks instantly:

Twig Profiler Call Graph

Symfony 2.7 enables the Twig profiler automatically when the application uses the debug mode. If you are using Twig outside of Symfony, you must register the new profiler extension before rendering the templates:

$profile = new Twig_Profiler_Profile();
$twig->addExtension(new Twig_Extension_Profiler($profile));

// render templates ...

$dumper = new Twig_Profiler_Dumper_Text();
echo $dumper->dump($profile);

In addition to the basic text dumper (which is the one used by Symfony), Twig also includes an advanced dumper to output the call graph information in a format compatible with the Blackfire Profiler.

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.


Great job ! :D
Nice idea! I like that :)
Awesome. Great job guys!!!!
A while ago I was facing this problem (profiling views) in RoR and haven't found anything good (New relic kinda helped). Glad to hear I won't have this problem with Sf2 :) Thanks!
Nice Tool ! Thx
Thanx !
Nice, thanks for this great improvement !
There's a lot of useful information! I've been waiting for this look, thanks!
Nice tool :)
Very usefull tool, specially the tree command !
Great job! Thanks!
Very good idea. Thank!
Nice tool !

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.