Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a8872de

Browse filesBrowse files
minor #50743 [DependencyInjection] Skip scanning scalar values in compiler passes when not needed (bastnic)
This PR was merged into the 6.4 branch. Discussion ---------- [DependencyInjection] Skip scanning scalar values in compiler passes when not needed | Q | A | ------------- | --- | Branch? | 6.4 | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - While profiling an app with ~2600 auto-discovered services, I figured out that we have a way bigger calls to string process that logic would expect. ![image](https://github.com/symfony/symfony/assets/84887/a1ea542d-5fe3-4c68-8183-4d3de150ed1f) ![image](https://github.com/symfony/symfony/assets/84887/ca2788e1-f0dd-4c61-ad36-0eecbe3a0110) Commits ------- f9f2baa [DependencyInjection] Skip scanning scalar values in compiler passes when not needed
2 parents 2fe2b5a + f9f2baa commit a8872de
Copy full SHA for a8872de

31 files changed

+72
-10
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
3131
*/
3232
protected $container;
3333
protected $currentId;
34+
protected bool $skipScalars = false;
3435

3536
private bool $processExpressions = false;
3637
private ExpressionLanguage $expressionLanguage;
@@ -77,6 +78,9 @@ protected function processValue(mixed $value, bool $isRoot = false)
7778
{
7879
if (\is_array($value)) {
7980
foreach ($value as $k => $v) {
81+
if ((!$v || \is_scalar($v)) && $this->skipScalars) {
82+
continue;
83+
}
8084
if ($isRoot) {
8185
if ($v->hasTag('container.excluded')) {
8286
continue;

‎src/Symfony/Component/DependencyInjection/Compiler/AliasDeprecatedPublicServicesPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AliasDeprecatedPublicServicesPass.php
+11-9Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,9 @@
1717

1818
final class AliasDeprecatedPublicServicesPass extends AbstractRecursivePass
1919
{
20-
private array $aliases = [];
21-
22-
protected function processValue(mixed $value, bool $isRoot = false): mixed
23-
{
24-
if ($value instanceof Reference && isset($this->aliases[$id = (string) $value])) {
25-
return new Reference($this->aliases[$id], $value->getInvalidBehavior());
26-
}
20+
protected bool $skipScalars = true;
2721

28-
return parent::processValue($value, $isRoot);
29-
}
22+
private array $aliases = [];
3023

3124
public function process(ContainerBuilder $container): void
3225
{
@@ -56,4 +49,13 @@ public function process(ContainerBuilder $container): void
5649

5750
parent::process($container);
5851
}
52+
53+
protected function processValue(mixed $value, bool $isRoot = false): mixed
54+
{
55+
if ($value instanceof Reference && isset($this->aliases[$id = (string) $value])) {
56+
return new Reference($this->aliases[$id], $value->getInvalidBehavior());
57+
}
58+
59+
return parent::processValue($value, $isRoot);
60+
}
5961
}

‎src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
*/
3333
class AnalyzeServiceReferencesPass extends AbstractRecursivePass
3434
{
35+
protected bool $skipScalars = true;
36+
3537
private ServiceReferenceGraph $graph;
3638
private ?Definition $currentDefinition = null;
3739
private bool $onlyConstructorArguments;

‎src/Symfony/Component/DependencyInjection/Compiler/AttributeAutoconfigurationPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AttributeAutoconfigurationPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
final class AttributeAutoconfigurationPass extends AbstractRecursivePass
2424
{
25+
protected bool $skipScalars = true;
26+
2527
private $classAttributeConfigurators = [];
2628
private $methodAttributeConfigurators = [];
2729
private $propertyAttributeConfigurators = [];

‎src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
*/
3636
class AutowirePass extends AbstractRecursivePass
3737
{
38+
protected bool $skipScalars = true;
39+
3840
private array $types;
3941
private array $ambiguousServiceTypes;
4042
private array $autowiringAliases;

‎src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredMethodsPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredMethodsPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*/
2222
class AutowireRequiredMethodsPass extends AbstractRecursivePass
2323
{
24+
protected bool $skipScalars = true;
25+
2426
protected function processValue(mixed $value, bool $isRoot = false): mixed
2527
{
2628
$value = parent::processValue($value, $isRoot);

‎src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredPropertiesPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredPropertiesPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
class AutowireRequiredPropertiesPass extends AbstractRecursivePass
2626
{
27+
protected bool $skipScalars = true;
28+
2729
protected function processValue(mixed $value, bool $isRoot = false): mixed
2830
{
2931
$value = parent::processValue($value, $isRoot);

‎src/Symfony/Component/DependencyInjection/Compiler/CheckArgumentsValidityPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/CheckArgumentsValidityPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
class CheckArgumentsValidityPass extends AbstractRecursivePass
2424
{
25+
protected bool $skipScalars = true;
26+
2527
private bool $throwExceptions;
2628

2729
public function __construct(bool $throwExceptions = true)

‎src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
class CheckExceptionOnInvalidReferenceBehaviorPass extends AbstractRecursivePass
2525
{
26+
protected bool $skipScalars = true;
27+
2628
private array $serviceLocatorContextIds = [];
2729

2830
/**

‎src/Symfony/Component/DependencyInjection/Compiler/CheckReferenceValidityPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/CheckReferenceValidityPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
class CheckReferenceValidityPass extends AbstractRecursivePass
2727
{
28+
protected bool $skipScalars = true;
29+
2830
protected function processValue(mixed $value, bool $isRoot = false): mixed
2931
{
3032
if ($isRoot && $value instanceof Definition && ($value->isSynthetic() || $value->isAbstract())) {

‎src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
*/
4242
final class CheckTypeDeclarationsPass extends AbstractRecursivePass
4343
{
44+
protected bool $skipScalars = true;
45+
4446
private const SCALAR_TYPES = [
4547
'int' => true,
4648
'float' => true,

‎src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*/
2828
class DecoratorServicePass extends AbstractRecursivePass
2929
{
30+
protected bool $skipScalars = true;
31+
3032
/**
3133
* @return void
3234
*/

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/DefinitionErrorExceptionPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
class DefinitionErrorExceptionPass extends AbstractRecursivePass
2727
{
28+
protected bool $skipScalars = true;
29+
2830
private array $erroredDefinitions = [];
2931
private array $targetReferences = [];
3032
private array $sourceReferences = [];

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
class InlineServiceDefinitionsPass extends AbstractRecursivePass
2626
{
27+
protected bool $skipScalars = true;
28+
2729
private ?AnalyzeServiceReferencesPass $analyzingPass;
2830
private array $cloningIds = [];
2931
private array $connectedIds = [];

‎src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
*/
3232
class RegisterServiceSubscribersPass extends AbstractRecursivePass
3333
{
34+
protected bool $skipScalars = true;
35+
3436
protected function processValue(mixed $value, bool $isRoot = false): mixed
3537
{
3638
if (!$value instanceof Definition || $value->isAbstract() || $value->isSynthetic() || !$value->hasTag('container.service_subscriber')) {

‎src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
class RemoveUnusedDefinitionsPass extends AbstractRecursivePass
2424
{
25+
protected bool $skipScalars = true;
26+
2527
private array $connectedIds = [];
2628

2729
/**

‎src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
class ReplaceAliasByActualDefinitionPass extends AbstractRecursivePass
2626
{
27+
protected bool $skipScalars = true;
28+
2729
private array $replacements;
2830

2931
/**

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
class ResolveBindingsPass extends AbstractRecursivePass
3030
{
31+
protected bool $skipScalars = true;
32+
3133
private array $usedBindings = [];
3234
private array $unusedBindings = [];
3335
private array $errorMessages = [];

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*/
2828
class ResolveChildDefinitionsPass extends AbstractRecursivePass
2929
{
30+
protected bool $skipScalars = true;
31+
3032
private array $currentPath;
3133

3234
protected function processValue(mixed $value, bool $isRoot = false): mixed

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveEnvPlaceholdersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveEnvPlaceholdersPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
class ResolveEnvPlaceholdersPass extends AbstractRecursivePass
2020
{
21+
protected bool $skipScalars = false;
22+
2123
protected function processValue(mixed $value, bool $isRoot = false): mixed
2224
{
2325
if (\is_string($value)) {

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveFactoryClassPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveFactoryClassPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
class ResolveFactoryClassPass extends AbstractRecursivePass
2121
{
22+
protected bool $skipScalars = true;
23+
2224
protected function processValue(mixed $value, bool $isRoot = false): mixed
2325
{
2426
if ($value instanceof Definition && \is_array($factory = $value->getFactory()) && null === $factory[0]) {

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveHotPathPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveHotPathPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
class ResolveHotPathPass extends AbstractRecursivePass
2525
{
26+
protected bool $skipScalars = true;
27+
2628
private array $resolvedIds = [];
2729

2830
/**

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
class ResolveNamedArgumentsPass extends AbstractRecursivePass
2626
{
27+
protected bool $skipScalars = true;
28+
2729
protected function processValue(mixed $value, bool $isRoot = false): mixed
2830
{
2931
if ($value instanceof AbstractArgument && $value->getText().'.' === $value->getTextWithContext()) {

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveNoPreloadPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveNoPreloadPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class ResolveNoPreloadPass extends AbstractRecursivePass
2424
{
2525
private const DO_PRELOAD_TAG = '.container.do_preload';
2626

27+
protected bool $skipScalars = true;
28+
2729
private array $resolvedIds = [];
2830

2931
/**

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
class ResolveParameterPlaceHoldersPass extends AbstractRecursivePass
2525
{
26+
protected bool $skipScalars = false;
27+
2628
private ParameterBagInterface $bag;
2729

2830
public function __construct(

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
class ResolveReferencesToAliasesPass extends AbstractRecursivePass
2424
{
25+
protected bool $skipScalars = true;
26+
2527
/**
2628
* @return void
2729
*/

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveServiceSubscribersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveServiceSubscribersPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
class ResolveServiceSubscribersPass extends AbstractRecursivePass
2525
{
26+
protected bool $skipScalars = true;
27+
2628
private ?string $serviceLocator = null;
2729

2830
protected function processValue(mixed $value, bool $isRoot = false): mixed

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveTaggedIteratorArgumentPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveTaggedIteratorArgumentPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class ResolveTaggedIteratorArgumentPass extends AbstractRecursivePass
2222
{
2323
use PriorityTaggedServiceTrait;
2424

25+
protected bool $skipScalars = true;
26+
2527
protected function processValue(mixed $value, bool $isRoot = false): mixed
2628
{
2729
if (!$value instanceof TaggedIteratorArgument) {

‎src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ final class ServiceLocatorTagPass extends AbstractRecursivePass
3030
{
3131
use PriorityTaggedServiceTrait;
3232

33+
protected bool $skipScalars = true;
34+
3335
protected function processValue(mixed $value, bool $isRoot = false): mixed
3436
{
3537
if ($value instanceof ServiceLocatorArgument) {

‎src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function resolveValue(mixed $value, array $resolving = []): mixed
198198
return $args;
199199
}
200200

201-
if (!\is_string($value) || 2 > \strlen($value)) {
201+
if (!\is_string($value) || '' === $value || !str_contains($value, '%')) {
202202
return $value;
203203
}
204204

‎src/Symfony/Component/Translation/DependencyInjection/TranslatorPathsPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/DependencyInjection/TranslatorPathsPass.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
class TranslatorPathsPass extends AbstractRecursivePass
2525
{
26+
protected bool $skipScalars = true;
27+
2628
private int $level = 0;
2729

2830
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.