Reputation: 71
I am facing problem from last few months that in my local environment the command cache:clear is incredibly slow. Many times it takes more than a minute. I tried it with both XAMPP and WAMP but It didn't help. I tried to solve by removing different services and bundles but situation remains same.
At the end I found the problem is directly proportionate to the number of Twig files I have in my Resources/Views Folder. I even created a new symfony project with standard command
composer create-project symfony/framework-standard-edition test-performance-project "2.7.*"
and created a simple standard controller and twig file to check my hypothesis. The more twig files I added in Resources/Views Folder, the slower the cache:clear command was (More or less proportional). Is there a way to prevent this because in our project we have high number of twig files in our Resources folder.
I am using
Windows 10 PHP 7.0.15 Symfony 2.7.23 Twig 1.31.0
Any help will be highly appreciated :)
Upvotes: 7
Views: 9802
Reputation: 1418
What did wonders for my cache:clear
speed was turning off the profiler with xdebug.profiler_enable = off
.
I was using WAMP, on Windows, with PHP 7.1 and 7.2.
With WAMP (but not only with it) the local webhost and your console may not be using the same php.ini file.
If you possibly inspect the phpinfo()
output in the browser, you may find that the profiler is turned off. But, when you run a cache:clear
in the console, the console may not be using the same php.ini file - as it was the case with me.
The php.ini really used from the console had the profiler running, which was causing PHP to create many GBs of cachegrind files, all in the background, hidden from me. I only noticed it when I inspected the Resource Manager's HDD usage, while the cache:clear
was happening.
When profiler was turned finally off, the cache:clear was at least 5 times faster.
Upvotes: 2
Reputation: 1354
Things I did to improve performance on windows 10, while keeping xdebug on.
enabled opcache
disabled xdebug.remote_autostart
added x-debug helper extension
Hint: if you have xdebug extension with remote_autostart 1, you should keep listener in your IDE always ON, even if you don't have any breakpoints, otherwise everything will run extremely slow (see case 6).
Some tests using a small symfony 4.2 project, in dev mode, time is DomContentLoaded taken from Chrome:
I use case 1 usually and when I need to debug I switch to case 2. Cases 3, 4, 5, 6 are relevant for people who might not be aware of implications of IDE listener and debug cookie.
I tested the same project with Windows Subsystem for Linux (WSL) enabled and got some improvements. load times when no caches were something like:
overall WSL improved everything, reducing load time by 50%.
PS: for WSL to work properly you will have to disable Windows Defender Real Time protection, otherwise everything will go 2x slower than without WSL. Maybe there are some options to keep Real Time protection on and exclude WSL, but I don't know at this point.
Upvotes: 5
Reputation: 1847
I had similar issue with xdebug enabled in my cli environment. Twig parsing does a lot of iterations over template files so xdebug has a huge impact on twig cache generation performance.
Try to comment out this line in your php cli configuration:
;zend_extension=xdebug.so
Upvotes: 8
Reputation: 589
A symfony core developer asked me that he always do rm -fr var/cache/*
so I always do this before running my app.
Also in config_dev.yml make template caching false
twig:
cache:false
Upvotes: -3