From 1dd3285c91deb275b63ffcb94e8a9c3efd6f3e8b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 20 Apr 2017 10:02:26 +0200 Subject: [PATCH] [DI] Reduce memory overhead of id normalization --- .../DependencyInjection/Dumper/PhpDumper.php | 13 ++++++------- .../Tests/Fixtures/php/services1-1.php | 4 ---- .../Tests/Fixtures/php/services1.php | 4 ---- .../Tests/Fixtures/php/services10.php | 4 ---- .../Tests/Fixtures/php/services12.php | 4 ---- .../Tests/Fixtures/php/services13.php | 4 ---- .../Tests/Fixtures/php/services19.php | 4 ---- .../Tests/Fixtures/php/services24.php | 4 ---- .../Tests/Fixtures/php/services26.php | 4 ---- .../Tests/Fixtures/php/services31.php | 4 ---- .../Tests/Fixtures/php/services32.php | 4 ---- .../Tests/Fixtures/php/services33.php | 2 -- .../Tests/Fixtures/php/services8.php | 4 ---- .../Tests/Fixtures/php/services9_compiled.php | 4 ---- .../services_dump_proxy_with_void_return_type.php | 4 ---- .../Tests/Fixtures/php/services_locator.php | 4 ---- .../Tests/Fixtures/php/services_private_frozen.php | 4 ---- .../Tests/Fixtures/php/services_subscriber.php | 3 --- 18 files changed, 6 insertions(+), 72 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 9b298f8c7a00f..f8259008ac7fb 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -938,17 +938,16 @@ public function isFrozen() */ private function addNormalizedIds() { - if (!$normalizedIds = $this->container->getNormalizedIds()) { - return ''; - } - - $code = " \$this->normalizedIds = array(\n"; + $code = ''; + $normalizedIds = $this->container->getNormalizedIds(); ksort($normalizedIds); foreach ($normalizedIds as $id => $normalizedId) { - $code .= ' '.$this->export($id).' => '.$this->export($normalizedId).",\n"; + if ($this->container->has($normalizedId)) { + $code .= ' '.$this->export($id).' => '.$this->export($normalizedId).",\n"; + } } - return $code." );\n"; + return $code ? " \$this->normalizedIds = array(\n".$code." );\n" : ''; } /** diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php index cdd91761b3b50..93df9e770fc96 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php @@ -28,10 +28,6 @@ class Container extends AbstractContainer public function __construct() { $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->aliases = array(); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php index 629448deb1562..9ad021ece802b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php @@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container public function __construct() { $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->aliases = array(); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php index d06dd5194bbe1..1cc1cc3d1644b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php @@ -29,10 +29,6 @@ public function __construct() $this->parameters = $this->getDefaultParameters(); $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->methodMap = array( 'test' => 'getTestService', ); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php index 119c0589cd1de..511127c1008d3 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php @@ -33,10 +33,6 @@ public function __construct() $this->parameters = $this->getDefaultParameters(); $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->methodMap = array( 'test' => 'getTestService', ); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php index 274651ce7d9b6..1cffb23b7b878 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php @@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container public function __construct() { $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->methodMap = array( 'bar' => 'getBarService', ); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php index 3d48492db49a1..8718efe078d3d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php @@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container public function __construct() { $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->methodMap = array( 'service_from_anonymous_factory' => 'getServiceFromAnonymousFactoryService', 'service_with_method_call_and_factory' => 'getServiceWithMethodCallAndFactoryService', diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php index be8cb0678c19a..6ccbbd31949f6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php @@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container public function __construct() { $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->methodMap = array( 'foo' => 'getFooService', ); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php index 9613de5775fb0..809d70da5e52a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php @@ -29,10 +29,6 @@ public function __construct() $this->parameters = $this->getDefaultParameters(); $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->methodMap = array( 'test' => 'getTestService', ); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services31.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services31.php index e6353d6e49b06..d22a130cd0514 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services31.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services31.php @@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container public function __construct() { $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->methodMap = array( 'bar' => 'getBarService', 'foo' => 'getFooService', diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services32.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services32.php index b86de7acaf032..08ca63092a6a6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services32.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services32.php @@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container public function __construct() { $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->methodMap = array( 'bar' => 'getBarService', 'foo' => 'getFooService', diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php index cde76531bb0c4..fe0510cc2602c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php @@ -28,8 +28,6 @@ public function __construct() { $this->services = array(); $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', 'symfony\\component\\dependencyinjection\\tests\\fixtures\\container33\\foo' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\Container33\\Foo', ); $this->methodMap = array( diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php index edd62bedf5192..bfc1d68bd1ef6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php @@ -29,10 +29,6 @@ public function __construct() $this->parameters = $this->getDefaultParameters(); $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->aliases = array(); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index eecae7fe79482..9ac0402f9d6b6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -29,10 +29,6 @@ public function __construct() $this->parameters = $this->getDefaultParameters(); $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->methodMap = array( 'bar' => 'getBarService', 'baz' => 'getBazService', diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_dump_proxy_with_void_return_type.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_dump_proxy_with_void_return_type.php index afb09b61c9d91..ec6af7fc2c8c5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_dump_proxy_with_void_return_type.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_dump_proxy_with_void_return_type.php @@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container public function __construct() { $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->methodMap = array( 'bar' => 'getBarService', 'foo' => 'getFooService', diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_locator.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_locator.php index 6ca318c5f5d90..ee94c019389c3 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_locator.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_locator.php @@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container public function __construct() { $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->methodMap = array( 'bar_service' => 'getBarServiceService', 'baz_service' => 'getBazServiceService', diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php index db80c72b16881..1fbfc52e4a077 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php @@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container public function __construct() { $this->services = array(); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->methodMap = array( 'bar_service' => 'getBarServiceService', 'baz_service' => 'getBazServiceService', diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php index 19611a1e4be7e..df5603572497f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php @@ -29,9 +29,6 @@ public function __construct() $this->services = array(); $this->normalizedIds = array( 'autowired.symfony\\component\\dependencyinjection\\tests\\fixtures\\customdefinition' => 'autowired.Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition', - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\tests\\fixtures\\customdefinition' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition', 'symfony\\component\\dependencyinjection\\tests\\fixtures\\testservicesubscriber' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber', ); $this->methodMap = array(