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

Skip to content

Commit 22c576b

Browse files
feature #49487 [FrameworkBundle] Allow disabling dumping of container to XML to improve performance (ruudk)
This PR was merged into the 6.3 branch. Discussion ---------- [FrameworkBundle] Allow disabling dumping of container to XML to improve performance | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | | License | MIT | Doc PR | In debug mode, when the container is compiled, an XML file is automatically generated. This file is used by various commands like: - `debug:container` - `lint:container` - `config:dump-reference` - `debug:autowiring` - `debug:router` But generating this file comes with a price. When your container grows, the XML file grows, and the time to compile this file increases. In our large application this file became 20MB and took 2 seconds to generate every time the cache needed to be recompiled. For us, the benefit of this file does not outweigh the decrease in performance. Therefore I'd like to disable this dumping and accept the consequences for less debug possibilities. To disable this, one can set the `debug.container.dump` parameter to `false`. Commits ------- 467fb3d Allow disabling dumping of container to XML
2 parents bacb274 + 467fb3d commit 22c576b

File tree

7 files changed

+22
-4
lines changed

7 files changed

+22
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CHANGELOG
1414
* Allow setting private services with the test container
1515
* Register alias for argument for workflow services with workflow name only
1616
* Configure the `ErrorHandler` on `FrameworkBundle::boot()`
17+
* Allow setting `debug.container.dump` to `false` to disable dumping the container to XML
1718

1819
6.2
1920
---

src/Symfony/Bundle/FrameworkBundle/Command/BuildDebugContainerTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function getContainerBuilder(KernelInterface $kernel): ContainerBuilde
3939
return $this->containerBuilder;
4040
}
4141

42-
if (!$kernel->isDebug() || !(new ConfigCache($kernel->getContainer()->getParameter('debug.container.dump'), true))->isFresh()) {
42+
if (!$kernel->isDebug() || !$kernel->getContainer()->getParameter('debug.container.dump') || !(new ConfigCache($kernel->getContainer()->getParameter('debug.container.dump'), true))->isFresh()) {
4343
$buildContainer = \Closure::bind(function () {
4444
$this->initializeBundles();
4545

src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private function getContainerBuilder(): ContainerBuilder
7777
$kernel = $this->getApplication()->getKernel();
7878
$kernelContainer = $kernel->getContainer();
7979

80-
if (!$kernel->isDebug() || !(new ConfigCache($kernelContainer->getParameter('debug.container.dump'), true))->isFresh()) {
80+
if (!$kernel->isDebug() || !$kernelContainer->getParameter('debug.container.dump') || !(new ConfigCache($kernelContainer->getParameter('debug.container.dump'), true))->isFresh()) {
8181
if (!$kernel instanceof Kernel) {
8282
throw new RuntimeException(sprintf('This command does not support the application kernel: "%s" does not extend "%s".', get_debug_type($kernel), Kernel::class));
8383
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ private function getContainerEnvVars(ContainerBuilder $container): array
292292
return [];
293293
}
294294

295-
if (!is_file($container->getParameter('debug.container.dump'))) {
295+
if (!$container->getParameter('debug.container.dump') || !is_file($container->getParameter('debug.container.dump'))) {
296296
return [];
297297
}
298298

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ContainerBuilderDebugDumpPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class ContainerBuilderDebugDumpPass implements CompilerPassInterface
3030
*/
3131
public function process(ContainerBuilder $container)
3232
{
33+
if (!$container->getParameter('debug.container.dump')) {
34+
return;
35+
}
36+
3337
$cache = new ConfigCache($container->getParameter('debug.container.dump'), true);
3438
if (!$cache->isFresh()) {
3539
$cache->write((new XmlDumper($container))->dump(), $container->getResources());

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
10871087

10881088
$debug = $container->getParameter('kernel.debug');
10891089

1090-
if ($debug) {
1090+
if ($debug && !$container->hasParameter('debug.container.dump')) {
10911091
$container->setParameter('debug.container.dump', '%kernel.build_dir%/%kernel.container_class%.xml');
10921092
}
10931093

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ public function testNoDebug()
5050
$this->assertStringContainsString('public', $tester->getDisplay());
5151
}
5252

53+
public function testNoDumpedXML()
54+
{
55+
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => true, 'debug.container.dump' => false]);
56+
57+
$application = new Application(static::$kernel);
58+
$application->setAutoExit(false);
59+
60+
$tester = new ApplicationTester($application);
61+
$tester->run(['command' => 'debug:container']);
62+
63+
$this->assertStringContainsString('public', $tester->getDisplay());
64+
}
65+
5366
public function testPrivateAlias()
5467
{
5568
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);

0 commit comments

Comments
 (0)