Replies: 6 comments
-
Why did you said But something looks really strange. Twig is known for being much much faster. You could try to profile your website with blackfire |
Beta Was this translation helpful? Give feedback.
-
I tested different options (corrected), yes with cache it is faster, but still much slower than before |
Beta Was this translation helpful? Give feedback.
-
|
We'll need a full reproducer to help you |
Beta Was this translation helpful? Give feedback.
-
|
I installed Xdebug and opened its log in KCacheGrind. Here you can see that after calling the load() script slowed down a lot. Do you have the ability to open my trace in KCacheGrind? Can this help?
|
Beta Was this translation helpful? Give feedback.
-
|
$loader = new \Twig\Loader\FilesystemLoader($appViewPaths);
$twig = new \Twig\Environment($loader, [
'debug' => false,
- 'cache' => false,
+ 'cache' => sys_get_temp_dir().'/twig_cache',
'autoescape' => 'html',
'charset' => 'utf-8',
]);
$twig->addFilter( new \Twig\TwigFilter('is_array', 'is_array') );
return $twig; |
Beta Was this translation helpful? Give feedback.
-
|
This does not solve the problem itself, but only slightly mitigates it. With the cache enabled, it still loads several times longer than the old version of the site with the cache disabled. |
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello. I recently rewrote my site to another engine and installed Twig 3 there. I found that the render file function with a minimum number of HTML tags and without any attachments or data is rendered for a very long time - 70 ms. While loading Twig itself takes only 14 ms. It is the render function that slows down the site a lot. Tell me where to look for the problem?
nginx, php - 8.4, twig - 3, cache = off, ssd speed 1.5Gb/s
public static function twig($viewDir = null, $getShared = true)
{
$appPaths = new \Config\Paths();
$appViewPaths = $viewDir ?? $appPaths->viewDirectory;
}
page.tpl
In the view() function I call twig:
$twig = \Config\Services::twig(); // 14ms
$tpl_data = [];
$template = $twig->render('page.tpl', $tpl_data); // 70ms
If I use insertion into the index.tpl (extends), the time increases to 200ms
The previous project had the same templates and they were loaded in !!! 9ms with insertion into the index.tpl
Previous version of the site - nginx, php 7.4, twig 2.15.5, cache = off
Beta Was this translation helpful? Give feedback.
All reactions