It is hard to define how much a call could cost. But I believe that call($a) cost less than call($b, $c) once that the second will use one argument more than first. So I think that is reasonable flip comparison based on number of arguments too.
I never heard about this (having any measurable performance impact) and even if, I would consider it an extreme micro optimisation...
Personally, I don't really like the idea of having this implemented, as it just feels like a really irrelevant optimisation.
It is about the probability of usage of arguments.
function call($argument1) {
$argument1 ** 2;
}
call(1);
function call($argument1, $argument2) {
$argument1 ** 2;
$argument2 ** 2;
}
call(1, 2);
How much arguments you have, _more probably_ is the complexity of code that uses it as argument. But it is not a rule (because of it, it is just a possibility generalized).
function call($argument1) {
return $argument1 ** 2;
}
function call($argument1, $argument2) {
return $argument1 + $argument2;
}
The first one is more complex/consumes more resources than the second example.
So, in general way, and while we can't calculate the real complexity of each case, I think that we can implements an additional suggestion to flip comparison based on how complex is the arguments.
I will think a way to test it with some benchmark code on internet, but I will do it later.
We will get a lot of false positives. It would be better to create complexity index for each function call and then compare it.
We will get a lot of false positives. It would be better to create complexity index for each function call and then compare it.
Well, might still be some kind of micro-optimisation, but for sure this approach is much more useful and will also have a higher performance impact.
Checked, it is a loooooot of false-positives.
Most helpful comment
We will get a lot of false positives. It would be better to create complexity index for each function call and then compare it.