Re:Optimizing dynamic JavaScript with inline caches
by Lerc on Friday April 07, 2017 @07:47PM
(#14064334)
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.
for instance
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 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.