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

Reduce function calls in creation of Item classes #182

Merged
merged 1 commit into from Jun 15, 2015
Merged

Reduce function calls in creation of Item classes #182

merged 1 commit into from Jun 15, 2015

Conversation

andrerom
Copy link
Contributor

@andrerom andrerom commented Sep 9, 2014

With heavy use of Stash creation of Item classes & setKey shows up
in profile data, so the change tries to reduce function calls in these.

Suggested followup is executeGet().
Note: Might need another pass on this tomorrow for CS / tests if this is otherwise accepted.
Note2: Contains interface change on Item to force array type on $key, felt like a easy way to avoid having to check.

@@ -99,36 +99,33 @@ public function setItemClass($class)
/**
* {@inheritdoc}
*/
public function getItem()
public function getItem($arg1, $arg2)
Copy link
Contributor

Choose a reason for hiding this comment

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

The second arg should default to null, so it can be called with one arg without a notice beeing emitted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true

@staabm
Copy link
Contributor

staabm commented Sep 10, 2014

Did you profile this change? Does it really make the function faster? A function call in php is not that expensive IMO.

The change to get ridd of func-get-args might indeed optimize it though

@andrerom
Copy link
Contributor Author

well depends on what you define as expensive, it is more then other languages, but compared to loading files it is of course not so high.

This is definitely micro optimization (see branch name), so I'm not saying this is a must. But given this is a caching library where you might consider using it as backend for Symfony Proxy (the one you use if you don't use Varnish) or in other micro frameworks, then every function call and file include counts in zend php (hhvm not so much) afaik, even if phpng might improve on this quite a bit.

* @param array $key
* @throws \InvalidArgumentException
*/
protected function setupKey($key)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: given the doc, this being protected and only being called from one place it seemed natural to move it into setKey, but might be doc is wrong and it is meant for subclassing Item class, however that is still not main focus of this class rigth? there is an interface now.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) when pulling 53a532e on andrerom:micro_optimizations into e0e3c12 on tedious:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) when pulling f835a35 on andrerom:micro_optimizations into e0e3c12 on tedious:master.

@andrerom
Copy link
Contributor Author

Unsure what the CS failure is about.
1) src/Stash/Item.php (extra_empty_lines)

@staabm
Copy link
Contributor

staabm commented Sep 11, 2014

Moving/removing the setupKey method is another BC break from this PR, because people might have subclassed i and rely on it beeing overridde

@andrerom
Copy link
Contributor Author

sub classing is not a extension point imho(interfaces are contracts, implementations are not), however fully I agree this PR should anyway be for 0.13 if accepted in current form given the changes to ItemInterface::setKey signature.

@tedivm
Copy link
Member

tedivm commented Sep 11, 2014

The next release is going to break BC anyways- we're pretty close to finalizing the FIG standard, after which I'll be focused on making Stash compliant and then reach towards a 1.0 release. Feel free to break all the shit you need.

@andrerom
Copy link
Contributor Author

:)

@andrerom
Copy link
Contributor Author

andrerom commented Jun 9, 2015

@tedivm Assuming you plan a new release (ref discussion on the bundle), any of these changes that would be of interest? I'll either rebase and cleanup, or close this one.

@tedivm
Copy link
Member

tedivm commented Jun 9, 2015

If you want to rebase and clean this up I'll merge it for the next release.

With heavy use of Stash creation of Item classes & setKey shows up
in profile data, so the change tries to reduce function calls in these.

Suggested followup is executeGet().
@andrerom
Copy link
Contributor Author

done, the failing test is composer not managing to pull in packages.

feel free to nitpick :)

tedivm added a commit that referenced this pull request Jun 15, 2015
Reduce function calls in creation of Item classes
@tedivm tedivm merged commit 3c05be0 into tedious:master Jun 15, 2015
@andrerom andrerom deleted the micro_optimizations branch June 15, 2015 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants