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

[DependencyInjection] Optimization of resolveEnvPlaceholders #44876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2022
Merged

[DependencyInjection] Optimization of resolveEnvPlaceholders #44876

merged 1 commit into from
Jan 12, 2022

Conversation

sveneld
Copy link
Contributor

@sveneld sveneld commented Dec 31, 2021

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
License MIT

When you have to much env variables and many services in your container, container compilаtion can take much time due to the function stripos which is called much time.
Look at the bottom of picture https://i2.piccy.info/i9/cdc413af9aecce8f7ed5ca0fe69b6c7c/1640950765/149173/1453384/6833Screenshot_from_2021_12_31_13_38_20.png

It happens because function resolveEnvPlaceholders try to find env placeholders in any value, even when there is no possible env in string.

So i offer to check value on strings env_ or env( and if they are present than look for placeholders.

In my project it helps me to save 10 seconds in container building.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot
Copy link

Hey!

I think @VincentLanglet has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@Kocal
Copy link
Member

Kocal commented Jan 2, 2022

Would it be possible to have Blackfire traces before/after your optimization?

@sveneld
Copy link
Contributor Author

sveneld commented Jan 2, 2022

@Kocal only xhprof

@carsonbot carsonbot changed the title Optimization of resolveEnvPlaceholders [DependencyInjection] Optimization of resolveEnvPlaceholders Jan 4, 2022
@Nyholm
Copy link
Member

Nyholm commented Jan 4, 2022

Great @sveneld, it would be interesting to see the before and after profiles

@sveneld
Copy link
Contributor Author

sveneld commented Jan 4, 2022

https://drive.google.com/drive/folders/1GoWngjjwXA6TQrGYix7xVk-LSLl3ijvp?usp=sharing

Main difference in Symfony\Component\DependencyInjection\ContainerBuilder::resolveEnvPlaceholders==>stripos it calls less

@sveneld
Copy link
Contributor Author

sveneld commented Jan 10, 2022

@Nyholm @Kocal have you looked?

@Kocal
Copy link
Member

Kocal commented Jan 10, 2022

Not at all, I asked this question in anticipation, in order to save time for the core team 😛

@sveneld
Copy link
Contributor Author

sveneld commented Jan 11, 2022

@nicolas-grekas can you look?

@nicolas-grekas
Copy link
Member

Thank you @sveneld.

@nicolas-grekas nicolas-grekas merged commit 6bffe41 into symfony:5.4 Jan 12, 2022
@sveneld
Copy link
Contributor Author

sveneld commented Jan 12, 2022

@nicolas-grekas when new tag with this code appear in 5.4 version?

@nicolas-grekas
Copy link
Member

Absolutely. We merge older branches into newer ones from time to time and before releases.

@sveneld sveneld deleted the optimization_resolveEnvPlaceholders branch January 12, 2022 13:18
fabpot added a commit that referenced this pull request Oct 20, 2022
…veneld)

This PR was merged into the 6.2 branch.

Discussion
----------

[DependencyInjection] Container building optimization

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| License       | MIT

When you have to much env variables and many services in your container, container compilаtion can take much time due to the function stripos which is called much time.

It happens because method freezeAfterProcessing try to find env placeholders in config, but make it in two foreach.
So i offer to get all possible placeholders with preg_match_all and do not use stripos for each placeholed.

Same situation with method resolveEnvPlaceholders. But in this method we should left stripos for hard cases when in value could be something like this 'env_1418b707a69b8575_const_HOST_74bcc04c4799f2ca10fb754fe5581c89env_1418b707a69b8575_const_CORE_URL_91ef68034c1e9e8b58c13725d3bafdc0'

In my project it helps me to save 40 seconds in container building.

Related to my previous fix #44876

Commits
-------

c886e2c [DependencyInjection] Container building optimization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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