Skip to content

Commit

Permalink
minor #26161 [DI] Top micro benchmarks (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.1-dev branch.

Discussion
----------

[DI] Top micro benchmarks

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This makes Symfony rank 1st most of the time, 2nd within the margin error otherwise.
Follow up of kocsismate/php-di-container-benchmarks#21

Commits
-------

3edf5f1 [DI] Top micro benchmarks
  • Loading branch information
chalasr committed Feb 13, 2018
2 parents 4ef0b3e + 3edf5f1 commit 4d6c481
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/Symfony/Component/DependencyInjection/Container.php
Expand Up @@ -217,21 +217,18 @@ public function has($id)
*/
public function get($id, $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1)
{
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}

// Re-use shared service instance if it exists.
if (isset($this->services[$id])) {
return $this->services[$id];
}
if ('service_container' === $id) {
return $this;
}
if (isset($this->factories[$id])) {
return $this->factories[$id]();
}
return $this->services[$id]
?? $this->services[$id = $this->aliases[$id] ?? $id]
?? ('service_container' === $id ? $this : ($this->factories[$id] ?? array($this, 'make'))($id, $invalidBehavior));

This comment has been minimized.

Copy link
@tecnocat

tecnocat Feb 26, 2018

Contributor

There is some reason to keep PHP 5.4 compatibility (array vs []) and using incompatible ?? from PHP 7?

Symfony team plans to upgrade to array short syntax anytime?

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Feb 26, 2018

Member

Branch 2.8 still requires array() and is maintained up to the end of the year.

This comment has been minimized.

Copy link
@tecnocat

tecnocat Feb 26, 2018

Contributor

Oh damn it! You are right!

}

/**
* Creates a service.
*
* As a separate method to allow "get()" to use the really fast `??` operator.
*/
private function make(string $id, int $invalidBehavior)
{
if (isset($this->loading[$id])) {
throw new ServiceCircularReferenceException($id, array_keys($this->loading));
}
Expand Down

0 comments on commit 4d6c481

Please sign in to comment.