Skip to content

[DependencyInjection] Slow performance when merging parameter bags #20198

@mickadoo

Description

@mickadoo

The pull request to allow injecting ENV parameters introduced an issue when building the container.

When a container is merged, the mergeEnvPlaceholders will duplicate existing placeholders. In a local project, where I had 9 env() parameters, this meant that the first 3 were duplicated 32768 times. Later when the compiler calls resolveEnvPlaceholders it will loop through all of these impacting performance pretty badly.

I think the problem is that using array_merge_recursive will append duplicate values of nested arrays if the keys are numeric. I've never contributed to Symfony before so I'm not sure on this one, but I don't know if it needs to be fully recursive given that the environment placeholders should be scalar values.

If it really does need to be recursive then something like the function mentioned in the comments for the array_merge_recursive docs page could be used. I did a simple performance check (microtime) for one of the compiler passes that was slowing down (ContainerBuilderDebugDumpPass)

0.023882150650024 # with the function from the comments in the php docs
16.744822025299 # as it is now
0.023157119750977 # with only one level merge

I'll create a pull request using the simple merge and see what you think.

I guess this won't affect anything before v3.2

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