Skip to content
This repository has been archived by the owner on Feb 6, 2020. It is now read-only.

Performance optimization #64

Merged

Conversation

snapshotpl
Copy link
Contributor

I have deeply reviewed code of v3 and I have found some interesting performance improvements.

  • we don't need to resolve name from aliases before search in existing services.
  • we don't need to resolve aliases any time - only when they are change
  • and my favourite: improve construction of ServiceManager. We don't need to validate overrides if we configure manager first time, so we can omit it. It improve creation time about 20-25%!

@snapshotpl
Copy link
Contributor Author

Strange. I don't know my master's tests pass, because composer missing Zend\Stdlib

@@ -15,7 +15,8 @@
},
"require": {
"php": "^5.5 || ^7.0",
"container-interop/container-interop": "~1.0"
"container-interop/container-interop": "~1.0",
"zendframework/zend-stdlib": "^2.4"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it used for make the test run then should be added to require-dev

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That class looks like a good candidate for optimization and for dropping a
dependency ;-)
On Jan 13, 2016 00:58, "Witold Wasiczko" notifications@github.com wrote:

In composer.json
#64 (comment)
:

@@ -15,7 +15,8 @@
},
"require": {
"php": "^5.5 || ^7.0",

  •    "container-interop/container-interop": "~1.0"
    
  •    "container-interop/container-interop": "~1.0",
    
  •    "zendframework/zend-stdlib": "^2.4"
    

It's used here
https://github.com/zendframework/zend-servicemanager/blob/master/src/Config.php#L62


Reply to this email directly or view it on GitHub
https://github.com/zendframework/zend-servicemanager/pull/64/files#r49533959
.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #68

@weierophinney weierophinney changed the title Perfomance optimalization Perfomance optimization Jan 13, 2016
@snapshotpl
Copy link
Contributor Author

#68 should fix tests

@@ -164,7 +171,6 @@ public function getServiceLocator()
public function get($name)
{
$requestedName = $name;
$name = isset($this->resolvedAliases[$name]) ? $this->resolvedAliases[$name] : $name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this will work. If you have an alias set, asking the alias the first time, then the resolved name the second time will create the instance two times instead of one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bakura10 this line is just move after next if statement. We don't need $name before this check

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, sorry! :)

@snapshotpl snapshotpl changed the title Perfomance optimization Performance optimization Jan 19, 2016
@snapshotpl
Copy link
Contributor Author

I have rebased to current stable master and all tests pass!

@bakura10
Copy link
Contributor

Looks good to me now :). Thanks for the improvement!

@@ -172,6 +178,8 @@ public function get($name)
return $this->services[$requestedName];
}

$name = isset($this->resolvedAliases[$name]) ? $this->resolvedAliases[$name] : $name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dang, wish we had PHP7's ?? for this.

@Ocramius
Copy link
Member

I just noticed that the entire benchmark setup is completely broken. Not good.

@bakura10
Copy link
Contributor

Yep. See that: #62

@Ocramius
Copy link
Member

@bakura10 no, it's not that. See

* @iterations 5000
*/
public function fetchFactoryService()
{
$result = $this->sm->get('factory_' . rand(0, self::NUM_SERVICES));
}

How many of those are actually new services? How many were already instantiated?

@bakura10
Copy link
Contributor

Haaaa. You're right!! Didn't spot that. Good catch.

@Ocramius
Copy link
Member

I'm currently migrating to phpbench to have some actual usable benchmark outputs (mainly because the output is too different between runs).

@snapshotpl
Copy link
Contributor Author

You have absolutely right. I had plan to fix that soon

@Ocramius
Copy link
Member

@snapshotpl hold yer horses: I'm sending a patch against your branch in a few.

@Ocramius
Copy link
Member

@snapshotpl see snapshotpl#1 - feel free to review/merge, it will be included in this PR afterwards.

@Ocramius Ocramius modified the milestones: 3.0.1, 3.0.2 Jan 24, 2016
…al-aliases-performance-optimization

Feature - zendframework#64 additional aliases performance optimization
@snapshotpl
Copy link
Contributor Author

@Ocramius looks great. Nice performance boost coming in next patch ;)

@bakura10
Copy link
Contributor

Great to see we still managed to squeeze a bit of performance (I honestly didn't think it was possible :-). Feel free to come with a 20% performance improvement to Zend Expressive too ^^.

@Ocramius
Copy link
Member

@bakura10 I see a lot of space for micro-optimizations with great impact in here, although it really needs phpbench/phpbench#252 before we even think of making the code harder to read :-P

@Ocramius Ocramius self-assigned this Jan 24, 2016
@Ocramius Ocramius mentioned this pull request Jan 24, 2016
@Ocramius Ocramius merged commit 10126b3 into zendframework:master Jan 24, 2016
Ocramius added a commit that referenced this pull request Jan 24, 2016
Ocramius added a commit that referenced this pull request Jan 24, 2016
Ocramius added a commit that referenced this pull request Jan 24, 2016
Ocramius pushed a commit that referenced this pull request Jan 24, 2016
…rformance-optimization

Feature - #64 additional aliases performance optimization
Ocramius added a commit that referenced this pull request Jan 24, 2016
Ocramius added a commit that referenced this pull request Jan 24, 2016
Ocramius added a commit that referenced this pull request Jan 24, 2016
Ocramius added a commit that referenced this pull request Jan 24, 2016
@Ocramius
Copy link
Member

@snapshotpl merged, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants