Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DI] dump factory files as classes #36193

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
Mar 31, 2020

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Mar 24, 2020

Q A
Branch? master
Bug fix? no
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

This PR is a performance improvement when using bin/console on the command line.

Once upon a time, we advised setting container.dumper.inline_factories to false so that the container could be chunked into many files. More recently, we turned this setting back to true in order to optimize for preloading. But this made bin/console back to slow: since the CLI cannot have opcache, PHP has to parse this potentially big file all the time. Previous data already showed this can grow big.

This PR fixes the issue by generating many files again. But instead of generating the inline code within each file, we now wrap this code inside a class. Then we list this class for preloading.

This way, we have the best of both worlds: a bin/console that scales no matter the size of the app and top perf when using preloading (I benched a small hello world before/after the patch with preloading enabled, there is no measurable difference.)

This should also fix a memory leak that happens when factory files contain closures.

@nicolas-grekas nicolas-grekas added this to the next milestone Mar 24, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.0 Mar 24, 2020
@nicolas-grekas nicolas-grekas modified the milestones: 5.0, next Mar 24, 2020
@nicolas-grekas nicolas-grekas force-pushed the di-dump-classes branch 2 times, most recently from c14f919 to 5f6bff5 Compare March 24, 2020 21:25
@nicolas-grekas nicolas-grekas merged commit 0876480 into symfony:master Mar 31, 2020
@nicolas-grekas nicolas-grekas deleted the di-dump-classes branch March 31, 2020 18:33
@@ -142,6 +142,10 @@ public function registerContainerConfiguration(LoaderInterface $loader)
}

$container->setAlias(static::class, 'kernel')->setPublic(true);

if (!$container->hasParameter('container.dumper.inline_factories')) {
$container->setParameter('container.dumper.inline_factories', false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be better to default container.dumper.inline_factories to false when the parameter is not given? you changed this to true in https://github.com/symfony/symfony/pull/34872/files#diff-f7b23d463cba27ac5e4cb677f2be7623R154. so just reverting this would make the default behavior as wanted or?

fabpot added a commit that referenced this pull request Apr 6, 2020
…ault (nicolas-grekas)

This PR was merged into the 5.1-dev branch.

Discussion
----------

Revert to container.dumper.inline_factories=false by default

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

As spotted by @Tobion in #36193 (review)

Commits
-------

2b6f1e9 Revert to container.dumper.inline_factories=false by default
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
fabpot added a commit that referenced this pull request Jun 28, 2020
…rvices (nicolas-grekas)

This PR was merged into the 5.1 branch.

Discussion
----------

[DI] fix minor perf regression when creating non-shared services

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #37401
| License       | MIT
| Doc PR        | -

This PR restores some dumped code that was too aggressively removed in  #36193.

Commits
-------

75e2ee1 [DI] fix minor perf regression when creating non-shared services
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.

3 participants