|
|
|
|
|
by jerven
3309 days ago
|
|
def clamp(num, min, max)
[min, num, max].sort[1]
end
being turned into def clamp(num, min, max)
if (num < min)
{
if (num < max)
return num;
else
return max;
}
if (min < max)
return min;
else return max;
end
Seems to me to be algorithm rewriting.
As is superword optimization and partial evaluation.
All things that Truffle-Ruby + Graal do today. |
|
That said, in my own limited experience, everyday optimisation problems tend to exist at a much higher level, on the high-level approach or "what are we doing" level. Perhaps these are "obvious" to some, or below the level of discussion here. But essentially, a compiler can optimise away endlessly at a piece of code, but will never beat code that shouldn't exist in the first place. My comment above was that a compiler has insufficient information to make decisions about what's truly wasteful or useless.
As an example, no compiler today will come up with a Courgette update [1] by itself. And the day it does, I think we can pack up our bags and go home (hopefully in a nice, comfy retirement kind of way).
[1] https://www.chromium.org/developers/design-documents/softwar...