Skip to content

Commit d323ecb

Browse files
author
Volodymyr Klymenko
authored
Merge pull request #302 from magento-performance/MAGETWO-54054
[Performance] Compiler Performance Optimisation
2 parents f66123e + aad8562 commit d323ecb

File tree

2 files changed

+83
-17
lines changed

2 files changed

+83
-17
lines changed

lib/internal/Magento/Framework/Module/Dir/Reader.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ class Reader
4646
*/
4747
protected $readFactory;
4848

49+
/**
50+
* Found configuration files grouped by configuration types (filename).
51+
*
52+
* @var array
53+
*/
54+
private $fileIterators = [];
55+
4956
/**
5057
* @param Dir $moduleDirs
5158
* @param ModuleListInterface $moduleList
@@ -65,24 +72,42 @@ public function __construct(
6572
}
6673

6774
/**
68-
* Go through all modules and find configuration files of active modules
75+
* Go through all modules and find configuration files of active modules.
6976
*
7077
* @param string $filename
7178
* @return FileIterator
7279
*/
7380
public function getConfigurationFiles($filename)
7481
{
75-
return $this->fileIteratorFactory->create($this->getFiles($filename, Dir::MODULE_ETC_DIR));
82+
return $this->getFilesIterator($filename, Dir::MODULE_ETC_DIR);
7683
}
7784

7885
/**
79-
* Go through all modules and find composer.json files of active modules
86+
* Go through all modules and find composer.json files of active modules.
8087
*
8188
* @return FileIterator
8289
*/
8390
public function getComposerJsonFiles()
8491
{
85-
return $this->fileIteratorFactory->create($this->getFiles('composer.json'));
92+
return $this->getFilesIterator('composer.json');
93+
}
94+
95+
/**
96+
* Retrieve iterator for files with $filename from components located in component $subDir.
97+
*
98+
* @param string $filename
99+
* @param string $subDir
100+
*
101+
* @return FileIterator
102+
*/
103+
private function getFilesIterator($filename, $subDir = '')
104+
{
105+
if (!isset($this->fileIterators[$subDir][$filename])) {
106+
$this->fileIterators[$subDir][$filename] = $this->fileIteratorFactory->create(
107+
$this->getFiles($filename, $subDir)
108+
);
109+
}
110+
return $this->fileIterators[$subDir][$filename];
86111
}
87112

88113
/**
@@ -96,9 +121,9 @@ private function getFiles($filename, $subDir = '')
96121
{
97122
$result = [];
98123
foreach ($this->modulesList->getNames() as $moduleName) {
99-
$moduleEtcDir = $this->getModuleDir($subDir, $moduleName);
100-
$file = $moduleEtcDir . '/' . $filename;
101-
$directoryRead = $this->readFactory->create($moduleEtcDir);
124+
$moduleSubDir = $this->getModuleDir($subDir, $moduleName);
125+
$file = $moduleSubDir . '/' . $filename;
126+
$directoryRead = $this->readFactory->create($moduleSubDir);
102127
$path = $directoryRead->getRelativePath($file);
103128
if ($directoryRead->isExist($path)) {
104129
$result[] = $file;
@@ -159,5 +184,6 @@ public function getModuleDir($type, $moduleName)
159184
public function setModuleDir($moduleName, $type, $path)
160185
{
161186
$this->customModuleDirs[$moduleName][$type] = $path;
187+
$this->fileIterators = [];
162188
}
163189
}

setup/src/Magento/Setup/Console/Command/DiCompileCommand.php

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
140140
'library' => $libraryPaths,
141141
'generated_helpers' => $generationPath
142142
];
143-
$excludedModulePaths = [];
144-
foreach ($modulePaths as $appCodePath) {
145-
$excludedModulePaths[] = '#^' . $appCodePath . '/Test#';
146-
}
147-
$excludedLibraryPaths = [];
148-
foreach ($libraryPaths as $libraryPath) {
149-
$excludedLibraryPaths[] = '#^' . $libraryPath . '/([\\w]+/)?Test#';
150-
}
151143
$this->excludedPathsList = [
152-
'application' => $excludedModulePaths,
153-
'framework' => $excludedLibraryPaths
144+
'application' => $this->getExcludedModulePaths($modulePaths),
145+
'framework' => $this->getExcludedLibraryPaths($libraryPaths),
154146
];
155147
$this->configureObjectManager($output);
156148

@@ -205,6 +197,54 @@ function (OperationInterface $operation) use ($progressBar) {
205197
}
206198
}
207199

200+
/**
201+
* Build list of module path regexps which should be excluded from compilation
202+
*
203+
* @param string[] $modulePaths
204+
* @return string[]
205+
*/
206+
private function getExcludedModulePaths(array $modulePaths)
207+
{
208+
$modulesByBasePath = [];
209+
foreach ($modulePaths as $modulePath) {
210+
$moduleDir = basename($modulePath);
211+
$vendorPath = dirname($modulePath);
212+
$vendorDir = basename($vendorPath);
213+
$basePath = dirname($vendorPath);
214+
$modulesByBasePath[$basePath][$vendorDir][] = $moduleDir;
215+
}
216+
217+
$basePathsRegExps = [];
218+
foreach ($modulesByBasePath as $basePath => $vendorPaths) {
219+
$vendorPathsRegExps = [];
220+
foreach ($vendorPaths as $vendorDir => $vendorModules) {
221+
$vendorPathsRegExps[] = $vendorDir
222+
. '/(?:' . join('|', $vendorModules) . ')';
223+
}
224+
$basePathsRegExps[] = $basePath
225+
. '/(?:' . join('|', $vendorPathsRegExps) . ')';
226+
}
227+
228+
$excludedModulePaths = [
229+
'#^(?:' . join('|', $basePathsRegExps) . ')/Test#',
230+
];
231+
return $excludedModulePaths;
232+
}
233+
234+
/**
235+
* Build list of library path regexps which should be excluded from compilation
236+
*
237+
* @param string[] $libraryPaths
238+
* @return string[]
239+
*/
240+
private function getExcludedLibraryPaths(array $libraryPaths)
241+
{
242+
$excludedLibraryPaths = [
243+
'#^(?:' . join('|', $libraryPaths) . ')/([\\w]+/)?Test#',
244+
];
245+
return $excludedLibraryPaths;
246+
}
247+
208248
/**
209249
* Delete directories by their code from "var" directory
210250
*

0 commit comments

Comments
 (0)