Skip to content

Commit 9cbdfc6

Browse files
bug #50905 [DepdencyInjection] Fix costly logic when checking errored definitions (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [DepdencyInjection] Fix costly logic when checking errored definitions | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #50763 (comment) | License | MIT | Doc PR | - `@NicolJamie` `@X`-Coder264 can you please give this patch a try and report back. Does that fix the perf issue you're having? Commits ------- 81adcd6 [DepdencyInjection] Fix costly logic when checking errored definitions
2 parents 99fa865 + 81adcd6 commit 9cbdfc6

File tree

1 file changed

+27
-41
lines changed

1 file changed

+27
-41
lines changed

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

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
class DefinitionErrorExceptionPass extends AbstractRecursivePass
2727
{
2828
private $erroredDefinitions = [];
29-
private $targetReferences = [];
3029
private $sourceReferences = [];
3130

3231
/**
@@ -37,45 +36,10 @@ public function process(ContainerBuilder $container)
3736
try {
3837
parent::process($container);
3938

40-
if (!$this->erroredDefinitions) {
41-
return;
42-
}
43-
44-
$runtimeIds = [];
45-
46-
foreach ($this->sourceReferences as $id => $sourceIds) {
47-
foreach ($sourceIds as $sourceId => $isRuntime) {
48-
if (!$isRuntime) {
49-
continue 2;
50-
}
51-
}
52-
53-
unset($this->erroredDefinitions[$id]);
54-
$runtimeIds[$id] = $id;
55-
}
56-
57-
if (!$this->erroredDefinitions) {
58-
return;
59-
}
60-
61-
foreach ($this->targetReferences as $id => $targetIds) {
62-
if (!isset($this->sourceReferences[$id]) || isset($runtimeIds[$id]) || isset($this->erroredDefinitions[$id])) {
63-
continue;
64-
}
65-
foreach ($this->targetReferences[$id] as $targetId => $isRuntime) {
66-
foreach ($this->sourceReferences[$id] as $sourceId => $isRuntime) {
67-
if ($sourceId !== $targetId) {
68-
$this->sourceReferences[$targetId][$sourceId] = false;
69-
$this->targetReferences[$sourceId][$targetId] = false;
70-
}
71-
}
72-
}
73-
74-
unset($this->sourceReferences[$id]);
75-
}
39+
$visitedIds = [];
7640

7741
foreach ($this->erroredDefinitions as $id => $definition) {
78-
if (isset($this->sourceReferences[$id])) {
42+
if ($this->isErrorForRuntime($id, $visitedIds)) {
7943
continue;
8044
}
8145

@@ -86,7 +50,6 @@ public function process(ContainerBuilder $container)
8650
}
8751
} finally {
8852
$this->erroredDefinitions = [];
89-
$this->targetReferences = [];
9053
$this->sourceReferences = [];
9154
}
9255
}
@@ -105,10 +68,8 @@ protected function processValue($value, bool $isRoot = false)
10568
if ($value instanceof Reference && $this->currentId !== $targetId = (string) $value) {
10669
if (ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) {
10770
$this->sourceReferences[$targetId][$this->currentId] ?? $this->sourceReferences[$targetId][$this->currentId] = true;
108-
$this->targetReferences[$this->currentId][$targetId] ?? $this->targetReferences[$this->currentId][$targetId] = true;
10971
} else {
11072
$this->sourceReferences[$targetId][$this->currentId] = false;
111-
$this->targetReferences[$this->currentId][$targetId] = false;
11273
}
11374

11475
return $value;
@@ -122,4 +83,29 @@ protected function processValue($value, bool $isRoot = false)
12283

12384
return parent::processValue($value);
12485
}
86+
87+
private function isErrorForRuntime(string $id, array &$visitedIds): bool
88+
{
89+
if (!isset($this->sourceReferences[$id])) {
90+
return false;
91+
}
92+
93+
if (isset($visitedIds[$id])) {
94+
return $visitedIds[$id];
95+
}
96+
97+
$visitedIds[$id] = true;
98+
99+
foreach ($this->sourceReferences[$id] as $sourceId => $isRuntime) {
100+
if ($visitedIds[$sourceId] ?? $visitedIds[$sourceId] = $this->isErrorForRuntime($sourceId, $visitedIds)) {
101+
continue;
102+
}
103+
104+
if (!$isRuntime) {
105+
return false;
106+
}
107+
}
108+
109+
return true;
110+
}
125111
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy