Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpKernel] Reduce memory consumption compiling container #18061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[HttpKernel] Fix mem usage when stripping the prod container
(cherry picked from commit c8cb253)
  • Loading branch information
nicolas-grekas authored and Peter Ward committed Mar 8, 2016
commit 3bb702a72b1cef1668bce7328ee519064974f3d3
18 changes: 12 additions & 6 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class PhpDumper extends Dumper
private $reservedVariables = array('instance', 'class');
private $targetDirRegex;
private $targetDirMaxMatches;
private $docStar;

/**
* @var \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface
Expand Down Expand Up @@ -97,7 +98,9 @@ public function dump(array $options = array())
$options = array_merge(array(
'class' => 'ProjectServiceContainer',
'base_class' => 'Container',
'debug' => true,
), $options);
$this->docStar = $options['debug'] ? '*' : '';

if (!empty($options['file']) && is_dir($dir = dirname($options['file']))) {
// Build a regexp where the first root dirs are mandatory,
Expand Down Expand Up @@ -589,7 +592,7 @@ private function addService($id, $definition)
$visibility = $isProxyCandidate ? 'public' : 'protected';
$code = <<<EOF

/**
/*{$this->docStar}
* Gets the '$id' service.$doc
*$lazyInitializationDoc
* $return
Expand Down Expand Up @@ -699,7 +702,7 @@ private function addServiceSynchronizer($id, Definition $definition)

return <<<EOF

/**
/*{$this->docStar}
* Updates the '$id' service.
*/
protected function synchronize{$this->camelize($id)}Service()
Expand Down Expand Up @@ -760,7 +763,7 @@ private function startClass($class, $baseClass)
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
$bagClass

/**
/*{$this->docStar}
* $class.
*
* This class has been auto-generated
Expand All @@ -786,7 +789,7 @@ private function addConstructor()

$code = <<<EOF

/**
/*{$this->docStar}
* Constructor.
*/
public function __construct()
Expand Down Expand Up @@ -823,7 +826,7 @@ private function addFrozenConstructor()

$code = <<<EOF

/**
/*{$this->docStar}
* Constructor.
*/
public function __construct()
Expand Down Expand Up @@ -970,11 +973,14 @@ public function getParameterBag()
return $this->parameterBag;
}
EOF;
if ('' === $this->docStar) {
$code = str_replace('/**', '/*', $code);
}
}

$code .= <<<EOF

/**
/*{$this->docStar}
* Gets the default parameters.
*
* @return array An array of the default parameters
Expand Down
5 changes: 1 addition & 4 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,7 @@ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container
$dumper->setProxyDumper(new ProxyDumper(md5((string) $cache)));
}

$content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'file' => (string) $cache));
if (!$this->debug) {
$content = static::stripComments($content);
}
$content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'file' => (string) $cache, 'debug' => $this->debug));

$cache->write($content, $container->getResources());
}
Expand Down