Skip to content

Navigation Menu

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

Slow and resourse greedy autowire of classes with large number of interfaces #49105

Copy link
Copy link
Closed
@DimanKuskov

Description

@DimanKuskov
Issue body actions

Symfony version(s) affected

5.4.0 and upper

Description

When class implements multiple interfaces, AutowirePass generates combined aliases for any set of implemented interfaces.
(see https://github.com/symfony/symfony/blob/v5.4.0/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php#L585)

This means that the set of combined aliases will be 2^(number of interfaces implemented) for this class. This results in exponential growth of time and memory required for container generation, resulting in slow or impossible run of cache:clear

25 three-letter-named interfaces will result in >10GB memory usage for cache:clear.

Neither PHP standart nor Symfony documentation do limit a number of possible interface number in class. Interfaces may be used to tag class and may be auto-generated in some cases. This makes above discribed situation, though rare, but possible. Furthermore, it is generally a bad practice to use algorithms with exponential difficulty where more quick algorithms can be used.

How to reproduce

  • Create new symfony project.
  • Create a reasonable amount of empty (marker) intefaces.
  • Create a class, that implements these interfaces.
  • Clear the cache.

These steps are done in https://github.com/DimanKuskov/symfony_issue

Possible Solution

  • Best solution is to completely rework handling of union types, searching for available implementation based on required union definition.
  • Quick solution would be not to try to generate all possible sets for classes with large amount of interfaces and produce a warning or error.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

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