This code configuration forces EM initialisation on bootstrap on each request - even if DB is not used.
Author: nikolay-dobromirovCreated Sep 16, 2026Updated Sep 16, 2026
Description
Move the configuration to a container compilation - thus eliminate the overhead for routes that do not use the EM instance.
I am observing this to cause 1-2ms overhead for bootstraps with no ORM calls in NewRelic.
Moving it to a compiler pass eliminates it fully.
Example
I managed to mitigate it with something like this. It should be quite similar in normal flow and eliminate the boot() overhead.
/**
* SyliusCoreBundle::boot() reads 'sylius_core.order_by_identifier' on every request and, if true,
* eagerly does $container->get('doctrine.orm.entity_manager')->getConfiguration()->setDefaultQueryHint(...),
* forcing the (otherwise lazy) default entity manager to build even on requests that never touch the DB.
*
* We bake the same hint into the entity manager's own Configuration definition at compile time instead
* (it becomes part of the EM's normal one-time construction, no separate eager fetch), then flip the
* parameter to false so Sylius's boot() skips its own runtime call. Net effect on ordering is unchanged.
*/
final class BakeOrderByIdentifierQueryHintPass implements CompilerPassInterface
{
private const PARAMETER = 'sylius_core.order_by_identifier';
private const CONFIGURATION_ID = 'doctrine.orm.default_configuration';
public function process(ContainerBuilder $container): void
{
if (!$container->hasParameter(self::PARAMETER)) {
return;
}
$wasEnabled = (bool) $container->getParameter(self::PARAMETER);
if ($wasEnabled && $container->hasDefinition(self::CONFIGURATION_ID)) {
$container->getDefinition(self::CONFIGURATION_ID)->addMethodCall('setDefaultQueryHint', [
Query::HINT_CUSTOM_TREE_WALKERS,
[OrderByIdentifierSqlWalker::class],
]);
}
$container->setParameter(self::PARAMETER, false);
}
}Source: Sylius/Sylius