3 ms·
I have been experimenting along these lines. Not so much aiming towards what is optimised but rather what is potentially optimisable. for instance funct
by Lerc 10y ago
I have been experimenting along these lines. Not so much aiming towards what is optimised but rather what is potentially optimisable.
for instance
function callerOfAll(fns) {
if (fns.length===0) return ()=>{};
if (fns.length === 1) return fns[0];
var first = fns.shift();
var rest = callerOfAll(fns);
return ()=>{first();rest();}
}
This should take a list of functions and return a function that calls them all. An optimiser should be able to inline the function call if it notices each rest() is only ever called once. Ultimately it could turn
[a,b,c,d,e] into ()=>(a();b();c();d();e());
or even further if those functions themselves are small enough to be inlinable.
Looking at V8 IR, it doesn't seem to get there.
I have wondered about making a benchmark suite out of such tricky but logically optimisable structures to give Javascript engines something to aim for.