Store TemplateClass in compiled includes - #3602
Conversation
Optimization for existing templates
| } | ||
|
|
||
| if ($template instanceof TemplateClass) { | ||
| return $this->env->loadClass($template->class, $template->name, $index); |
There was a problem hiding this comment.
Here is the shortcut.
|
I see a big issue here: the output of compiling a template now depends on the template class name of included templates, which makes cache invalidation a lot harder (if you add a new template matching a name in a higher priority location, it will not be consistently used depending on whether the templates referencing that name are already cached with the old class name or no) |
|
I try to optimize the use-case where the templates are immutable: a typical Symfony application on production. This change should not create any issue in that conditions. But you are right, that it can create inconsistencies during development or if the loader has variable results. An other idea was to add cache to the |
|
The performance benefits is not worth the added complexity. That was interesting to dive into this code |
Trying to optimize calls to
hashfunction (#3588), I found that the template classes could be cached inside the calling templates.Example with the following template
{% include '@ResponsiveFront/home/views/metas.html.twig' with { Metadata } only %}Compiled version:
Previous compiled version:
If the direction is OK, I'd continue with all other types of template calls (extends, embed, use, macro ...)