Description
Symfony version(s) affected
5.3.99
Description
The translation commands scan the same files multiple times. In a large project with multiple locales this process takes more than 30 minutes to complete
How to reproduce
I created a reproducer that simply consists of a controller action that has the Translator component autowired
https://github.com/E-M-P-I-R-E/bug-symfony-container-reproducer
Both of the two translation commands are affected
bin/console translation:update en --force
bin/console debug:translation en
When adding a dump()
statement on line 142 in vendor\symfony\translation\Extractor\PhpExtractor.php
I see that the controller is parsed twice
filename: "ContainerTestController.php"
...
filename: "ContainerTestController.php"
Possible Solution
It appears that (since translator is injected) the controller is being selected to be parsed by this class that populates the commands' constructor $codePaths
argument: vendor\symfony\translation\DependencyInjection\TranslatorPathsPass.php
The commands also add the src
directory to the $codePaths
to be parsed. There was some discussion in #40229 about whether that should be hardcoded. This seems to be the reason it's scanned twice. I don't understand the need for scanning the entire src
directory when the TranslatorPathsPass
already selects all classes that include TranslatorInterface
Perhaps @yceruto or @natewiebe13 have some insight about this behavior
Additional Context
As a work around to skip parsing source files entirely and only scan templates it is possible to provide a path to the bundle argument ex.
bin/console translation:update en /path/to/project --force