Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[EventDispatcher] small optimization#19312
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
[EventDispatcher] small optimization#19312
Uh oh!
There was an error while loading.Please reload this page.
Conversation
fabpot commentedJul 8, 2016
We don't make "performance optimization" without proofs that it indeed improves performance significantly. Can you tell us what kind of improvement you see with your changes? |
cheprasov commentedJul 8, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@fabpot Because And I did test yesterday upd. |
eugene-matvejev commentedJul 8, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
previously I seen that guys submithttps://blackfire.io/ metrics with PR, may be that will solve problem? |
| { | ||
| if (null ===$eventName) { | ||
| return(bool)count($this->listenerIds) || (bool)count($this->listeners); | ||
| returncount($this->listenerIds) ||count($this->listeners); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
what aboutreturn $this->listenerIds || $this->listeners?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks. Fixed.
Result of performance test.
+-------+------------------------+-------+------------------+---------------------+-------+| GROUP | NAME | COUNT | TIME | SINGLE | COST |+-------+------------------------+-------+------------------+---------------------+-------+| Test | count($a) || count($b) | 1000 | 0.40582633018494 | 0.00040582633018494 | 123 % || Test | $a || $b | 1000 | 0.32871198654175 | 0.00032871198654175 | 100 % |+-------+------------------------+-------+------------------+---------------------+-------+nicolas-grekas commentedJul 10, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
👍 (with |
| { | ||
| if (null ===$eventName) { | ||
| return(bool)count($this->listenerIds) ||(bool)count($this->listeners); | ||
| return$this->listenerIds ||$this->listeners; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
In#19320 we rejected to replacecount() withempty(). Imo we should be consistent with our decisions here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Indeed. I think the current expression better conveys the intent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
#19320 was a broad PR changing everything at once. On a case by case basis, we not to me.
I this case, casting to bool feels strange. At least, I'd expect0 < count(...). But personally (and I know I'm not the usual guy concerning CS), I prefer the proposed way. Less steps in my personal PHP virtual machine :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Changing this line toreturn 0 < count($this->listenerIds) || 0 < count($this->listeners); would be okay for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Why we need to usereturn 0 < count($this->listenerIds) || 0 < count($this->listeners) ?
Do you want be sure, that you will get bool?
But, if I use logical operators (||, &&, and so on) I will get bool.
For example,return 10 || 0; you will not get 10, you will get result of logical operation, it will betrue, we do not need to convert it to bool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think debating this is pointless. Let's keep what we already have as it works and let's move on.
cheprasovJul 13, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Maybe is better to write clear and optimized code and use comments and annotations for easy understanding?
I think, some constructions like asreturn 0 < count($this->listenerIds) || 0 < count($this->listeners) is not easier to understanding, or it maybe easier, for people, who do not know php enough well.
I believe, to use code constructions that have excess of logic is not correct way to build great and fast framework.
eugene-matvejevJul 13, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I am not Symfony person, and I can't decide, but whenever you attend LondonPHP meetups, good speakers advertise to write clean code [and I agree with them], which I think this PR aiming for, if it get us tiny performance improvement I think we should consider to adopt it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Please, define "clean code" in this context.
theofidryJul 15, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
As someone not familiar with this piece of code,return 0 < count($this->listenerIds) || 0 < count($this->listeners); looks much easier to understand thanreturn (bool) count($this->listenerIds) || (bool) count($this->listeners) andreturn $this->listenerIds || $this->listeners;.
Uh oh!
There was an error while loading.Please reload this page.
$this->listenerIds || $this->listenersreturnsboolisset($params[0])is faster and safer thanis_array($params)