Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[DI] fix preloading script generation#36103
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
d443a87
to312a112
CompareThis pollutes the codebase... 😞 |
Pierstoval commentedMar 17, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Is there a way to provide a "default" preloading script for all packages (that will execute these |
nicolas-grekas commentedMar 17, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
see the description why this is needed.
That's not possible, because the list of classes that need to be preloaded is conditional: vendor/ containing a package doesn't mean in any way it's going to be used at runtime. Putting the |
Yeah, I know it's necessary to fix the preload, but is this really worth it? |
What I mean is, even if the preload is not perfect, it's not fundamentally broken, even if the performance is not as good as it could be. Is getting preload working such a priority that it's worth peppering these all over the codebase? |
@teohhanhui the numbers speak by themselves I think... |
Nyholm left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thank you Nicolas for working on this. I like that you managed to add tests to this feature.
I agree that this adds “class_exists” all over the place that can be hard to understand why. But once this PHP feature has matured one can safely remove these extra lines of code.
The performance benefit is impressive. Big 👍 for me.
rvanlaak commentedMar 17, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The Would introducing a new trait method to provide additional context via the method's name and phpdoc provide the same performance boost? trait PreloaderTrait {publicfunctionpreload(string ...$classNames):void {foreach($classNamesas$className) {class_exists($className); } }} useSymfony\PreloaderTrait;preload( FilesystemCache::class, CoreExtension::class, EscaperExtension::class, OptimizerExtension::class, StagingExtension::class, ExtensionSet::class); |
nicolas-grekas commentedMar 17, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Actually not: this will remain and should become a new practice: we'll have to tell somewhere which classes are always needed by the implementations. Here are the options:
@rvanlaak this doesn't work, we need code thatruns - a trait doesn't "run". |
The
|
nicolas-grekas commentedMar 17, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The |
ludofleury commentedMar 17, 2020
Impressive performance. at +50% it worth the maintenance cost. Hands down. |
Now with this comment before all calls: |
👍 The comments sure are helpful |
Plopix commentedMar 18, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
+1 for me as well. As usual: thanks a lot! |
Thanks Nicolas! This is truly impressive! Just asking: have you tried these changes in the Symfony Demo app? Should we expect similar ~50% performance improvements? Thanks! |
Thank you@nicolas-grekas. |
This is the same idea as when we add list of classes that we were concatenating in one file to make things faster. Definitely worth the extra manual work. |
nicolas-grekas commentedMar 18, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks@fabpot @javiereguiluz no way you'll see 50% on the demo apps. It'd be surprising if it'd spend that much time doing only loading. I hope real apps do a bit more :) |
…lare extra classes to preload/services to not preload (nicolas-grekas)This PR was merged into the 5.1-dev branch.Discussion----------[DI] add tags `container.preload`/`.no_preload` to declare extra classes to preload/services to not preload| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| Deprecations? | no| Tickets | -| License | MIT| Doc PR | -To allow fine-grained declaration of sidekick classes in DI extensions.Follows#36103Commits-------fb04711 [DI] add tags `container.preload`/`.no_preload` to declare extra classes to preload/services to not preload
Uh oh!
There was an error while loading.Please reload this page.
(fabbot failure is a false positive)
On master, we should work on being able to preload more classes (esp. all cache-warmup artifacts).
But for 4.4, this is good enough. Submitted as a bug fix because 1. the current code that deals with preloading kinda-works, but only on "dev" mode... and 2. fixing it provides a nice boost!
Small bench on a hello world:
That's +50%!
Pro-tip: adding a few
class_exists()
as done in this PR for the classes that are always used in the implementations (e.g.new Foo()
in the constructor) will help the preload-script generator to work optimally. Without them, it will discover the symbols to preload only if they're found on methods.Some of those
class_exists()
are mandatory, in relation to anonymous classes andhttps://bugs.php.net/79349