javascript - How to make closure compiler to remove all dead code with advanced optimization in larger projects? -
the following code:
function f(a) { a.a = 5; return a; } f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {}); f(function() {});
is optimized closure compiler this:
function a(){return function(){}}function b(c){c.a=5}b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());
(it leaves dead code.)
however, if remove last line (repeat calling 24x), removes dead code. result empty.
how can force closure compiler remove dead code in larger projects?
the difference whether compiler decides inline "f" or not. once inlined "(function(){}).a = 5" dead expression. before "f" function has side-effects (it modifies parameters) , not removable on own.
the decision inline based on estimate whether inlining result in smaller code size. change 24 25 in case tipping point when cost of inlining estimated more saved removing function definition.
Comments
Post a Comment