-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #25474 [DI] Optimize Container::get() for perf (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [DI] Optimize Container::get() for perf | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25159 | License | MIT | Doc PR | - As outlined in #25159, our beloved container suffers from a perf hit just because it has a second argument, and this second argument's default value makes it slower. Let's fix this by inlining the value. This will put Symfony at a better rank on eg: https://github.com/kocsismate/php-di-container-benchmarks I benched also with the following script. The result is surprising (but matches the finding in #25159): without the patch, it takes 2s, and with the patch, it's down to 1s (opcache enabled). ```php require './vendor/autoload.php'; use Symfony\Component\DependencyInjection\Container; $c = new Container(); $c->set('foo', new \stdClass()); $i = 10000000; $s = microtime(1); while (--$i) { $c->get('foo'); } echo microtime(true) - $s, "\n"; ``` Commits ------- 4fe2551 [DI] Optimize Container::get() for perf
- Loading branch information
Showing
3 changed files
with
10 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters