Skip to content

[DI] Allow dumping the container in one file instead of many files #32581

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
Jul 31, 2019

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 4.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Replaces #32119
As spotted by @lyrixx, putting all service factories in one big container can be easier to manage with workers. It could also play well with PHP7.4's preloading.

This PR adds a container.dumper.inline_factories parameter to enable this behavior.
When it is set to true, a single big container file is created.

@lyrixx
Copy link
Member

lyrixx commented Jul 17, 2019

This will need some tests. At least functional tests, to unsure we can boot() the kernel (several times)

@nicolas-grekas nicolas-grekas force-pushed the dic-no-files branch 3 times, most recently from 4c1a9b2 to 685ff7f Compare July 17, 2019 17:13
@nicolas-grekas
Copy link
Member Author

Unit tests added.

At least functional tests, to unsure we can boot() the kernel (several times)

not added because this would be unrelated: this PR changes absolutely nothing in terms of how the container is loaded.

@fabpot
Copy link
Member

fabpot commented Jul 19, 2019

What are the pros/cons of setting container.dumper.inline_factories to true/false? Do we really need two modes?

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Jul 19, 2019

We demonstrated in the past that loading a set of smaller files is faster than loading a single big container file. The drawback that @lyrixx experienced is found on workers: because they are long-running, they are more likely to be affected by the removal of one of those files. This doesn't happen for requests that reload everything all the time.

What is unknown is how PHP 7.4 will change the situation regarding performance. With preloading, a single big file can, in theory, be similarly fast or faster. But anyway, we're not going to support only PHP 7.4. If that's confirmed, we'll be able to have a recipe that sets this param to true on PHP 7.4, and drop that in Symfony 6.

@Tobion
Copy link
Contributor

Tobion commented Jul 19, 2019

The drawback that @lyrixx experienced is found on workers: because they are long-running, they are more likely to be affected by the removal of one of those files.

Why would a file be removed? Sounds like a deployment problem.

@nicolas-grekas
Copy link
Member Author

On dev I suppose, it disrupts the workflow.

@lyrixx
Copy link
Member

lyrixx commented Jul 19, 2019

Yes it's in development of course 👍
As soon as you change a constructor the cache is built again
So running consumers explode

@nicolas-grekas
Copy link
Member Author

I'm merging this to move forward. We might consider defaulting or sticking to one way or another, but we need to be able to compare first.

@nicolas-grekas nicolas-grekas merged commit c893986 into symfony:4.4 Jul 31, 2019
nicolas-grekas added a commit that referenced this pull request Jul 31, 2019
…f many files (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[DI] Allow dumping the container in one file instead of many files

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Replaces #32119
As spotted by @lyrixx, putting all service factories in one big container can be easier to manage with workers. It could also play well with PHP7.4's preloading.

This PR adds a `container.dumper.inline_factories` parameter to enable this behavior.
When it is set to true, a single big container file is created.

Commits
-------

c893986 [DI] Allow dumping the container in one file instead of many files
@lyrixx
Copy link
Member

lyrixx commented Aug 1, 2019

Thanks @nicolas-grekas for this one :)

OskarStark added a commit to symfony/symfony-docs that referenced this pull request Jan 14, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

Fix OPcache class preload requirement

`container.dumper.inline_factories`
As stated by @nicolas-grekas in symfony/symfony#32581 (comment)
> With preloading, a single big file can, in theory, be similarly fast or faster.

`container.dumper.inline_class_loader`
With this parameter set to `true`, we'll do extra `include_once` for classes already preloaded by OPcache.
Additionally, it can lead to warnings (cannot redeclare class) in classes that use `class_alias`, like https://github.com/FriendsOfSymfony/FOSHttpCacheBundle/blob/master/src/EventListener/InvalidationListener.php#L33
It's because this class already declared in preload, and PHP tries to declare it again after `include_once` in service getter.

Commits
-------

cc151fc Remove incorrect opcache preload instructions
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.

6 participants