-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] fix preloading script generation #36103
New issue
< 8000 details-dialog class="Box Box--overlay d-flex flex-column anim-fade-in fast overflow-auto" aria-label="Sign up for GitHub">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
Conversation
d443a87
to
312a112
Compare
This pollutes the codebase... 😞 |
Is there a way to provide a "default" preloading script for all packages (that will execute these |
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... |
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.
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 {
public function preload(string ... $classNames): void
{
foreach($classNames as $className) {
class_exists($className);
}
}
} use Symfony\PreloaderTrait;
preload(
FilesystemCache::class,
CoreExtension::class,
EscaperExtension::class,
OptimizerExtension::class,
StagingExtension::class,
ExtensionSet::class
); |
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 that runs - a trait doesn't "run". |
The
|
The |
Impressive performance. at +50% it worth the maintenance cost. Hands down. |
312a112
to
a10fc4d
Compare
Now with this comment before all calls: |
👍 The comments sure are helpful |
+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. |
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 #36103 Commits ------- fb04711 [DI] add tags `container.preload`/`.no_preload` to declare extra classes to preload/services to not preload
(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 and https://bugs.php.net/79349