-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Optimize PHP preloading #42855
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
Conversation
e320c71
to
9b68844
Compare
@@ -342,7 +342,7 @@ class %s extends {$options['class']} | |||
|
|||
$code[$options['class'].'.preload.php'] .= <<<'EOF' | |||
|
|||
Preloader::preload($classes); | |||
$preloaded = Preloader::preload($classes); |
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.
is this variable used anywhere ?
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.
yes, when you run bin/console cache:clear --env=prod --no-debug
you end with this file var/cache/prod/App_KernelProdContainer.preload.php
: (real file from a real project)
<?php
// This file has been auto-generated by the Symfony Dependency Injection Component
// You can reference it in the "opcache.preload" php.ini setting on PHP >= 7.4 when preloading is desired
use Symfony\Component\DependencyInjection\Dumper\Preloader;
if (in_array(PHP_SAPI, ['cli', 'phpdbg'], true)) {
return;
}
require dirname(__DIR__, 3).'/vendor/autoload.php';
require __DIR__.'/ContainerWzBLRqh/App_KernelProdContainer.php';
// ...
$classes = [];
$classes[] = 'Symfony\Bundle\FrameworkBundle\FrameworkBundle';
// ...
$preloaded = Preloader::preload($classes);
require_once __DIR__.'/twig/ed/ed5588e4aa2c633d6e4d1ab3a4513d9ba8365c3d12ebf428cc741d0da77555cd.php';
require_once __DIR__.'/twig/49/499cbd92134d953c76afb5025f1db3a2ab80405e5971f6477a4893d6928ad6b1.php';
require_once __DIR__.'/twig/70/704863ffbc575094d43b51f64894f32131dfa045a8849be92596d5a3ef3bb124.php';
require_once __DIR__.'/twig/31/31ea17e321effcd4f6b72864a9ba4eee5a3849c2c2436548fbebd21f2a3dc823.php';
require_once __DIR__.'/twig/d0/d0b8370d51aa15d688c5fb120a8b4aa0bad0e8d0d83b82f0844d231fc5b55dab.php';
require_once __DIR__.'/twig/4b/4bdeb26a0aab0c783ca61a2abee99bf90b433575fa5a94018934045559ee92c4.php';
require_once __DIR__.'/twig/75/757a58fcce449e67afd245d7b534220bfa904be6bb609fee1d3697f190e643b5.php';
require_once __DIR__.'/twig/a0/a0e10cd2137ef92e0c2830af70a0f2dcb1735c3df7a8b75a5301452b9c0ff318.php';
require_once __DIR__.'/twig/5f/5f2b87645662d27d37e09186986a410fff2c2832049772faf3e5cd525990fc33.php';
require_once __DIR__.'/twig/a1/a10f955a1b640aaaac06ac7f68d3212517ed58bcef5fc6662ef960a1696999fe.php';
require_once __DIR__.'/twig/b8/b8361b189000a17b07c5a71e1d332cee5b494b7536c74ffdaf5d5bca005d7a62.php';
require_once __DIR__.'/twig/d9/d9c6b24a80943c5e6a8cf92f3cee97848164b499eb8d4ac8a927db166c05017a.php';
require_once __DIR__.'/twig/69/697075e5aee5dcff27ae63ee1760644f903f8f339acb93e3c94ae934d87c1ff7.php';
require_once __DIR__.'/twig/95/95405ba95db8b50746810a48a9717b91f03d37902660a21b8cd42544ca2ad2bb.php';
require_once __DIR__.'/twig/63/63757e44a1693f2e575b4d97e6d48061d850b4487005a36eee679beec51d5868.php';
require_once __DIR__.'/twig/d5/d5ff445375b9931f663b70a3ca0322fe9c4abfb814ec746b782e09b4f79cd9ef.php';
require_once __DIR__.'/twig/11/112b39f1c877dd6764f788b7576d3bf6aa84c28f6884d9d554b652f3036bb36b.php';
require_once __DIR__.'/twig/8a/8a16aca553faf2413588e3b4949150fb831140a8238bdfbc32fad4b921dddd99.php';
require_once __DIR__.'/twig/33/33cdddcb0de0b87241956866a55e8cb7d53b2f3fd5e827984f53123805c8ae26.php';
require_once __DIR__.'/twig/4b/4b95e8c57f4f0d295bb47af900ba46f6f55da1cbe14b43e0457076bff217b583.php';
require_once __DIR__.'/twig/87/8731269ece3a9764a7f799d4c4b0bcb87e712f11071daaf2b821365836d18ae3.php';
$classes = [];
$classes[] = 'Symfony\\Component\\Validator\\Mapping\\ClassMetadata';
$classes[] = 'Symfony\\Component\\Form\\Extension\\Validator\\Constraints\\Form';
$classes[] = 'Symfony\\Component\\Routing\\Generator\\CompiledUrlGenerator';
$classes[] = 'Symfony\\Bundle\\FrameworkBundle\\Routing\\RedirectableCompiledUrlMatcher';
$preloaded = Preloader::preload($classes, $preloaded);
So the preloaded is given to the next call to Preloader::preload
, and so we avoid reploading again all files
And in my case, I divide by two the number of warning
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.
Where is this $preloaded = Preloader::preload($classes, $preloaded);
coming from ? I don't see it in your diff.
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.
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.
Just one question and good to me.
Thank you @lyrixx. |
I'm trying to solve a warning when my app is booting:
It looks like it's not fixable since PHP parse all the file,
even if the class declaration is wrapped in an
if (false)
statement.But anyway, I found some optimisations
$preloaded
var, to avoid parsing the same list many times(
Preloader::preload()
) is called many times invar/cache/prod/App_KernelProdContainer.preload.php
class_exist
before using the reflection to avoid a useless throw / catch.