Skip to content

Commit f2c01dc

Browse files
minor #36193 [DI] dump factory files as classes (nicolas-grekas)
This PR was merged into the 5.1-dev branch. Discussion ---------- [DI] dump factory files as classes | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - This PR is a performance improvement when using `bin/console` on the command line. Once upon a time, we advised setting `container.dumper.inline_factories` to `false` so that the container could be chunked into many files. More recently, we turned this setting back to `true` in order to optimize for preloading. But this made `bin/console` back to slow: since the CLI cannot have opcache, PHP has to parse this potentially big file all the time. Previous data already showed this can grow big. This PR fixes the issue by generating many files again. But instead of generating the inline code within each file, we now wrap this code inside a class. Then we list this class for preloading. This way, we have the best of both worlds: a `bin/console` that scales no matter the size of the app and top perf when using preloading (I benched a small hello world before/after the patch with preloading enabled, there is no measurable difference.) This should also fix a memory leak that happens when factory files contain closures. Commits ------- cedb5cd429 [DI] dump factory files as classes
2 parents 92250ca + 4e8d3f3 commit f2c01dc

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Kernel/MicroKernelTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ public function registerContainerConfiguration(LoaderInterface $loader)
142142
}
143143

144144
$container->setAlias(static::class, 'kernel')->setPublic(true);
145+
146+
if (!$container->hasParameter('container.dumper.inline_factories')) {
147+
$container->setParameter('container.dumper.inline_factories', false);
148+
}
145149
});
146150
}
147151

0 commit comments

Comments
 (0)