0

I am in the process of milking out every byte possible out of a library i am writing using the google closure compiler.

The library consists of two files:

I am compiling with ADVANCED_OPTIMIZATIONS using the closure builder, the options i use are in the 'compile' key of this grunt config.

Reading the compiled file i can see a few symbols not being compiled like they should. I even took advantage of this fact and omitted exporting one method, and it got exported (addListener). Other methods only get "uncompiled" if i export them, like the removeListener.

So the compiled code where symbols are exported looks like this:

var k = e;
k.C = g;
var l = g.prototype;
l.addCheck = l.j;
l.check = l.k;
l.addCheckListener = l.r;
l.removeCheckListener = l.s;
l.removeListener = l.removeListener; // why is that?
// taking advantage of addListener not being compressed, i omitted it, so saved
// a few more bytes:
// l.addListener = l.addListener; <----
l.isDone = l.o;
l.isDoneCheck = l.p;
k.C.prototype = l;
window.ss = {
    ready: k
};

Why is that happening and what can i do to further optimize resulting code size?

As a bonus question, i created two private methods in an effort to reduce the use of setTimeout and delete in the compiled code. However the compiler chose to inline all the calls i made to these methods resulting in having the uncompressed delete and setTimeout calls multiple times in the compiled source.

e.g.

function rem(obj, key) { delete obj[key]; }
function doStuff() { 
    var anObject = {key:1};
    rem(anObject, 'key'); // 'key' isn't really a string literal in the code
}

This gets compiled to:

function a(){var b={z:1}; delete b.z}

Any tips on avoiding that too?

Cheers

thanpolas
  • 848
  • 1
  • 8
  • 20

1 Answers1

1

For the first look at the closure compiler wiki pages for typed based property renaming ( https://code.google.com/p/closure-compiler/wiki/ExperimentalTypeBasedPropertyRenaming ). For the second look at the compiler faq regarding string inlining ( https://code.google.com/p/closure-compiler/wiki/FAQ#Closure_Compiler_inlined_all_my_strings,_which_made_my_code_size ) and answer the question: do you care only about pre-gzip size.

John
  • 5,443
  • 15
  • 21
  • Hey @john, thank you for the reply. I [searched](http://code.google.com/p/closure-compiler/w/list?can=1&q=type+optimization&colspec=PageName+Summary+Changed+ChangedBy) on the closure compiler wiki for typed based optimizations but could not find anything relevant... What did you have in mind? – thanpolas Jul 04 '12 at 11:41
  • Updated my comment with links – John Jul 04 '12 at 17:46