Skip to content

Commit 1842e12

Browse files
committed
bug #36103 [DI] fix preloading script generation (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [DI] fix preloading script generation | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - (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: - before: 380 req/s - after: 580 req/s 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 Commits ------- a10fc4da5d [DI] fix preloading script generation
2 parents c8fd3e9 + c950a43 commit 1842e12

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

FrameworkBundle.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerWeakRefPass;
2424
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
2525
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\WorkflowGuardListenerPass;
26+
use Symfony\Component\Cache\Adapter\ApcuAdapter;
27+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
28+
use Symfony\Component\Cache\Adapter\ChainAdapter;
29+
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
30+
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
2631
use Symfony\Component\Cache\DependencyInjection\CacheCollectorPass;
2732
use Symfony\Component\Cache\DependencyInjection\CachePoolClearerPass;
2833
use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
@@ -32,6 +37,7 @@
3237
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
3338
use Symfony\Component\DependencyInjection\Compiler\RegisterReverseContainerPass;
3439
use Symfony\Component\DependencyInjection\ContainerBuilder;
40+
use Symfony\Component\Dotenv\Dotenv;
3541
use Symfony\Component\ErrorHandler\ErrorHandler;
3642
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
3743
use Symfony\Component\Form\DependencyInjection\FormPass;
@@ -58,6 +64,19 @@
5864
use Symfony\Component\Validator\DependencyInjection\AddAutoMappingConfigurationPass;
5965
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
6066
use Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass;
67+
use Symfony\Component\VarExporter\Internal\Hydrator;
68+
use Symfony\Component\VarExporter\Internal\Registry;
69+
70+
// Help opcache.preload discover always-needed symbols
71+
class_exists(ApcuAdapter::class);
72+
class_exists(ArrayAdapter::class);
73+
class_exists(ChainAdapter::class);
74+
class_exists(PhpArrayAdapter::class);
75+
class_exists(PhpFilesAdapter::class);
76+
class_exists(Dotenv::class);
77+
class_exists(ErrorHandler::class);
78+
class_exists(Hydrator::class);
79+
class_exists(Registry::class);
6180

6281
/**
6382
* Bundle.

Routing/Router.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@
2020
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
2121
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
2222
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
23+
use Symfony\Component\Routing\Annotation\Route;
2324
use Symfony\Component\Routing\RequestContext;
2425
use Symfony\Component\Routing\RouteCollection;
2526
use Symfony\Component\Routing\Router as BaseRouter;
2627

28+
// Help opcache.preload discover always-needed symbols
29+
class_exists(RedirectableCompiledUrlMatcher::class);
30+
class_exists(Route::class);
31+
2732
/**
2833
* This Router creates the Loader only when the cache is empty.
2934
*

0 commit comments

Comments
 (0)