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

Skip to content

Commit f3fc6d7

Browse files
committed
feature #48802 [DependencyInjection] Cut compilation time (nicolas-grekas)
This PR was merged into the 6.3 branch. Discussion ---------- [DependencyInjection] Cut compilation time | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Two more victories for Blackfire.io 🎉 First win for InlineServiceDefinitionsPass: -58% ![image](https://user-images.githubusercontent.com/243674/209802991-e985525a-4e03-4cb6-b43a-b3e7e530344a.png) Second win for `ContainerBuilder::inVendors()`: an additional -6.5% ![image](https://user-images.githubusercontent.com/243674/209803312-90a8b343-68f3-4392-b834-2fd3404cab8a.png) Confirmed -50% without Blackfire also: from 30s to 15s. Commits ------- 87cf70a [DependencyInjection] Cut compilation time
2 parents f79d848 + 87cf70a commit f3fc6d7

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function process(ContainerBuilder $container)
5151
$analyzedContainer = $container;
5252
}
5353
try {
54+
$notInlinableIds = [];
5455
$remainingInlinedIds = [];
5556
$this->connectedIds = $this->notInlinedIds = $container->getDefinitions();
5657
do {
@@ -60,7 +61,8 @@ public function process(ContainerBuilder $container)
6061
}
6162
$this->graph = $analyzedContainer->getCompiler()->getServiceReferenceGraph();
6263
$notInlinedIds = $this->notInlinedIds;
63-
$this->connectedIds = $this->notInlinedIds = $this->inlinedIds = [];
64+
$notInlinableIds += $this->notInlinableIds;
65+
$this->connectedIds = $this->notInlinedIds = $this->inlinedIds = $this->notInlinableIds = [];
6466

6567
foreach ($analyzedContainer->getDefinitions() as $id => $definition) {
6668
if (!$this->graph->hasNode($id)) {
@@ -86,7 +88,7 @@ public function process(ContainerBuilder $container)
8688
} while ($this->inlinedIds && $this->analyzingPass);
8789

8890
foreach ($remainingInlinedIds as $id) {
89-
if (isset($this->notInlinableIds[$id])) {
91+
if (isset($notInlinableIds[$id])) {
9092
continue;
9193
}
9294

@@ -126,8 +128,10 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
126128

127129
$definition = $this->container->getDefinition($id);
128130

129-
if (!$this->isInlineableDefinition($id, $definition)) {
130-
$this->notInlinableIds[$id] = true;
131+
if (isset($this->notInlinableIds[$id]) || !$this->isInlineableDefinition($id, $definition)) {
132+
if ($this->currentId !== $id) {
133+
$this->notInlinableIds[$id] = true;
134+
}
131135

132136
return $value;
133137
}
@@ -188,7 +192,7 @@ private function isInlineableDefinition(string $id, Definition $definition): boo
188192
return true;
189193
}
190194

191-
if ($this->currentId == $id) {
195+
if ($this->currentId === $id) {
192196
return false;
193197
}
194198
$this->connectedIds[$id] = true;

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
114114
*/
115115
private array $vendors;
116116

117+
/**
118+
* @var string[] the list of paths in vendor directories
119+
*/
120+
private array $pathsInVendor = [];
121+
117122
/**
118123
* @var array<string, ChildDefinition>
119124
*/
@@ -1610,17 +1615,27 @@ private function getExpressionLanguage(): ExpressionLanguage
16101615

16111616
private function inVendors(string $path): bool
16121617
{
1618+
$path = is_file($path) ? \dirname($path) : $path;
1619+
1620+
if (isset($this->pathsInVendor[$path])) {
1621+
return $this->pathsInVendor[$path];
1622+
}
1623+
16131624
$this->vendors ??= (new ComposerResource())->getVendors();
16141625
$path = realpath($path) ?: $path;
16151626

1627+
if (isset($this->pathsInVendor[$path])) {
1628+
return $this->pathsInVendor[$path];
1629+
}
1630+
16161631
foreach ($this->vendors as $vendor) {
16171632
if (str_starts_with($path, $vendor) && false !== strpbrk(substr($path, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
16181633
$this->addResource(new FileResource($vendor.'/composer/installed.json'));
16191634

1620-
return true;
1635+
return $this->pathsInVendor[$path] = true;
16211636
}
16221637
}
16231638

1624-
return false;
1639+
return $this->pathsInVendor[$path] = false;
16251640
}
16261641
}

0 commit comments

Comments
 (0)