8000 [TwigBundle] TemplateCacheWarmer processes non-template files · Issue #34142 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[TwigBundle] TemplateCacheWarmer processes non-template files #34142
Closed
@m-vo

Description

@m-vo

Symfony version(s) affected: >= 2.8.0
(not sure exactly, probably as soon as the TemplateCacheWarmer was introduced)

Description
The template cache warmer loads (lexes, compiles, ...) all files the default template iterator is listing. This may include images and other non-templates inside /templates, /app/Resources/views, any bundles resource paths and so on.

foreach ($this->iterator as $template) {
try {
$this->twig->load($template);
} catch (Error $e) {
// problem during compilation, give up
// might be a syntax error or a non-Twig template
}
}

This can consume quite a lot of memory (and processing time). In fact for large files this fails completely. If you want to try this yourself do the following:

  1. create a large dummy file inside your default template path (800MB in this example):
    dd if=/dev/zero of=file.txt count=1024 bs=781250
  2. warm the cache: bin/console cache:warm
  3. wait...
In Compiler.php line 129: Error:
Field width 3200000000 is too long

In my opinion it's wrong to include random files in the cache warming process. One could argue that putting those files inside the template/views folders is a bad practice to begin with but Symfony does so as well and it allows to include assets like so: {{ include('@Twig/images/symfony-logo.svg') }}.

Conclusion
In theory every file could be a twig template that's content needs to be parsed but it should imo have a .twig file extension in this case. Like mylogo.svg.twig or template.html5.twig. (← these files potentially aren't valid svgs or html5 documents and you'd probably have setup your IDE to enable Twig language support based on the file extension anyway)

Possible Solution
Add a callback filter iterator or a condition inside the TemplateCacheWarmer that strips all files without a .twig extension before calling $twig->load($template).

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRFCRFC = Request For Comments (proposals about features that you want to be discussed)StalledTwigBundle

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0