Sylius version affected: 1.2.4
Newer versions should be impacted.
Description
The first load of sylius is crazy slow.
Steps to reproduce
Put 22k files into your theme, in many directories (like a node_modules/).
Possible Solution
Here is the slow trace:
https://blackfire.io/profiles/9792cc36-3001-4d5a-b029-9c8328b1ca46/graph
Here is the fast trace, without the node_modules/ directory:
https://blackfire.io/profiles/ef740f72-6a56-4542-aff6-269b4068864a/graph
The function which is causing the "issue" is:
\Sylius\Bundle\ThemeBundle\Translation\Finder\TranslationFilesFinder::findTranslationFiles
public function findTranslationFiles(string $path): array
{
$themeFiles = $this->getFiles($path);
$translationsFiles = [];
foreach ($themeFiles as $themeFile) {
$themeFilepath = (string) $themeFile;
if (!$this->isTranslationFile($themeFilepath)) {
continue;
}
$translationsFiles[] = $themeFilepath;
}
return $translationsFiles;
}
We found out that trying to find all the translation files in a node_modules/ directory can be very painful.
The discussion on Slack starts here: https://sylius-devs.slack.com/archives/C5K44R5GU/p1553722188005300
A related PR: https://github.com/Sylius/Sylius/pull/9013
Some solutions:
node_modules/ because this is the main scenario…The good thing is that we can implement all these solutions and it will be amazing!
Thank you 💪 ❤️
Thanks for reporting! We have extracted ThemeBundle development to a standalone repository here: https://github.com/Sylius/SyliusThemeBundle, I'd move it there but the GitHub feature for that is broken.
I think the fix might be to improve this finder to only look for files in translations and */translations directories in the theme as they're the only ones.
The next move would be to cache them during warmup, this is a bit trickier if we want to have seamless developer experience, but definitely doable.
If one wants to fix this issue, please send a PR to the 1.3 branch in Sylius/SyliusThemeBundle repository.
As Kamil said, issue is related to SyliusThemeBundle, which is not a part of this monorepo anymore :)