Optimizing dynamic JavaScript with inline caches
github.com
github.com
Does this actually work? I tried it out in the Chrome Debugger and it didn't work. It looks like the author is confusing it with Rusts match statement.
> dividers[2](6)
3
> dividers[undefined](6, 3)
2 var divider = dividers[divisor] || dividers[undefined];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.