Skip to content

Commit

Permalink
Merge pull request #327 from magento-performance/MAGETWO-57905
Browse files Browse the repository at this point in the history
Story:
- MAGETWO-57905: Compiler Performance Optimization for 2.1
  • Loading branch information
MomotenkoNatalia authored Sep 7, 2016
2 parents 25339b5 + 000873d commit 259955f
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 17 deletions.
40 changes: 33 additions & 7 deletions lib/internal/Magento/Framework/Module/Dir/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ class Reader
*/
protected $readFactory;

/**
* Found configuration files grouped by configuration types (filename).
*
* @var array
*/
private $fileIterators = [];

/**
* @param Dir $moduleDirs
* @param ModuleListInterface $moduleList
Expand All @@ -65,24 +72,42 @@ public function __construct(
}

/**
* Go through all modules and find configuration files of active modules
* Go through all modules and find configuration files of active modules.
*
* @param string $filename
* @return FileIterator
*/
public function getConfigurationFiles($filename)
{
return $this->fileIteratorFactory->create($this->getFiles($filename, Dir::MODULE_ETC_DIR));
return $this->getFilesIterator($filename, Dir::MODULE_ETC_DIR);
}

/**
* Go through all modules and find composer.json files of active modules
* Go through all modules and find composer.json files of active modules.
*
* @return FileIterator
*/
public function getComposerJsonFiles()
{
return $this->fileIteratorFactory->create($this->getFiles('composer.json'));
return $this->getFilesIterator('composer.json');
}

/**
* Retrieve iterator for files with $filename from components located in component $subDir.
*
* @param string $filename
* @param string $subDir
*
* @return FileIterator
*/
private function getFilesIterator($filename, $subDir = '')
{
if (!isset($this->fileIterators[$subDir][$filename])) {
$this->fileIterators[$subDir][$filename] = $this->fileIteratorFactory->create(
$this->getFiles($filename, $subDir)
);
}
return $this->fileIterators[$subDir][$filename];
}

/**
Expand All @@ -96,9 +121,9 @@ private function getFiles($filename, $subDir = '')
{
$result = [];
foreach ($this->modulesList->getNames() as $moduleName) {
$moduleEtcDir = $this->getModuleDir($subDir, $moduleName);
$file = $moduleEtcDir . '/' . $filename;
$directoryRead = $this->readFactory->create($moduleEtcDir);
$moduleSubDir = $this->getModuleDir($subDir, $moduleName);
$file = $moduleSubDir . '/' . $filename;
$directoryRead = $this->readFactory->create($moduleSubDir);
$path = $directoryRead->getRelativePath($file);
if ($directoryRead->isExist($path)) {
$result[] = $file;
Expand Down Expand Up @@ -159,5 +184,6 @@ public function getModuleDir($type, $moduleName)
public function setModuleDir($moduleName, $type, $path)
{
$this->customModuleDirs[$moduleName][$type] = $path;
$this->fileIterators = [];
}
}
60 changes: 50 additions & 10 deletions setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
'library' => $libraryPaths,
'generated_helpers' => $generationPath
];
$excludedModulePaths = [];
foreach ($modulePaths as $appCodePath) {
$excludedModulePaths[] = '#^' . $appCodePath . '/Test#';
}
$excludedLibraryPaths = [];
foreach ($libraryPaths as $libraryPath) {
$excludedLibraryPaths[] = '#^' . $libraryPath . '/([\\w]+/)?Test#';
}
$this->excludedPathsList = [
'application' => $excludedModulePaths,
'framework' => $excludedLibraryPaths
'application' => $this->getExcludedModulePaths($modulePaths),
'framework' => $this->getExcludedLibraryPaths($libraryPaths),
];
$this->configureObjectManager($output);

Expand Down Expand Up @@ -205,6 +197,54 @@ function (OperationInterface $operation) use ($progressBar) {
}
}

/**
* Build list of module path regexps which should be excluded from compilation
*
* @param string[] $modulePaths
* @return string[]
*/
private function getExcludedModulePaths(array $modulePaths)
{
$modulesByBasePath = [];
foreach ($modulePaths as $modulePath) {
$moduleDir = basename($modulePath);
$vendorPath = dirname($modulePath);
$vendorDir = basename($vendorPath);
$basePath = dirname($vendorPath);
$modulesByBasePath[$basePath][$vendorDir][] = $moduleDir;
}

$basePathsRegExps = [];
foreach ($modulesByBasePath as $basePath => $vendorPaths) {
$vendorPathsRegExps = [];
foreach ($vendorPaths as $vendorDir => $vendorModules) {
$vendorPathsRegExps[] = $vendorDir
. '/(?:' . join('|', $vendorModules) . ')';
}
$basePathsRegExps[] = $basePath
. '/(?:' . join('|', $vendorPathsRegExps) . ')';
}

$excludedModulePaths = [
'#^(?:' . join('|', $basePathsRegExps) . ')/Test#',
];
return $excludedModulePaths;
}

/**
* Build list of library path regexps which should be excluded from compilation
*
* @param string[] $libraryPaths
* @return string[]
*/
private function getExcludedLibraryPaths(array $libraryPaths)
{
$excludedLibraryPaths = [
'#^(?:' . join('|', $libraryPaths) . ')/([\\w]+/)?Test#',
];
return $excludedLibraryPaths;
}

/**
* Delete directories by their code from "var" directory
*
Expand Down

0 comments on commit 259955f

Please sign in to comment.