Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing getting parents by given type #9217

Closed
wants to merge 22 commits into from
Closed

Optimizing getting parents by given type #9217

wants to merge 22 commits into from

Conversation

sivajik34
Copy link
Contributor

@sivajik34 sivajik34 commented Apr 12, 2017

We can optimize type's parents info by storing into an array,so that next time onwards we can return this array with out calculating whole logic.

@adragus-inviqa
Copy link
Contributor

You shouldn't use underscores for private/protected members.

Do you have some numbers? How much time does this save?

@sivajik34
Copy link
Contributor Author

@adragus-inviqa
Magento core team using underscores.
i don't know exactly how much time it will save or not.maybe useful to store into array without calculating again whole thing.

@adragus-inviqa
Copy link
Contributor

Yeah, they shouldn't be using underscores. Must be some legacy code. But I'll wait for them to confirm.

Whenever you optimise stuff, you need to come up with numbers, to actually prove that your change is needed. Is it saving a fraction of a second or 2 minutes?

Every refactoring can introduce bugs, so your PR needs to be justified. With numbers.

@sivajik34
Copy link
Contributor Author

@adragus-inviqa i agree. can you give some idea to check the improvement.
I mean some tools,script to get actual numbers?
i think i can use profiler.

@@ -8,6 +8,11 @@
class ClassReader implements ClassReaderInterface
{
/**
* @var array
*/
protected $_classNameParents;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid using underscores in property names, it is a legacy standard.
There is no need for this property to be protected as we do not encourage inheritance-based APIs

Copy link
Contributor Author

@sivajik34 sivajik34 Apr 17, 2017

Choose a reason for hiding this comment

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

@ishakhsuvarov so can i use private $classNameParents?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that is what I meant :)

}
array_unshift($result, $parentClass);
if (isset($this->_classNameParents[$className])) {
return $this->_classNameParents[$className];
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like there is no more need for the else

@@ -120,6 +120,7 @@ public function getInstanceType($instanceName)
*/
public function getPreference($type)
{
$type = ltrim($type, '\\');
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not look like a part of in-object cache, which is the purpose of this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

I think OP has mixed up branches a bit: #9189 (comment)

@@ -53,7 +53,6 @@ public function __construct(FactoryInterface $factory, ConfigInterface $config,
*/
public function create($type, array $arguments = [])
{
$type = ltrim($type, '\\');
return $this->_factory->create($this->_config->getPreference($type), $arguments);
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not look like a part of in-object cache, which is the purpose of this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ishakhsuvarov can i remove these changes and sent only changes related to this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that would be perfect.

}
array_unshift($result, $parentClass);
if (isset($this->_classNameParents[$className])) {
return $this->_classNameParents[$className];
Copy link
Contributor

Choose a reason for hiding this comment

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

Please consider updating tests to verify this case.

@ishakhsuvarov
Copy link
Contributor

@sivajik34 Thank you for the PR. Idea looks good overall, however please check review comments.
Some numbers would be good as well.

@ishakhsuvarov
Copy link
Contributor

Hi @sivajik34
Are you going to proceed with this PR?
Thanks!

@sivajik34
Copy link
Contributor Author

@ishakhsuvarov if its not that much helpful we can close it.no issues.

@ishakhsuvarov
Copy link
Contributor

@sivajik34
Ok. Thank you for collaboration

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

Successfully merging this pull request may close these issues.

3 participants