Slimmer with --hardcore

http://www.issuetrackerproduct.com/Documentation#slimmer

6th of May 2006

Last week I wrote about a hope of slimming "private functions in Javascript" but realized that it was futile since it's not really possible. It led me to another idea where I rewrite all long-named functions within the code and relabel them at the end. The idea is that code that looks like this:

 function parseSomething(z) {
   ...
 }
 function foo(x, y) {
     return parseSomething(x) + parseSomething(y);
 }
 foo(1,2);

becomes this:

 function _A(z) {
   ...
 }
 function _B(x, y) {
     return _A(x) + _A(y);
 }
 _B(1,2);
 var parseSomething=_A;

None of the functionality is ruined and in this case we save about 10bytes.

It's not a huge save but that's also why it only takes effect if you use the --hardcore parameter. The --hardcore parameter also corrects the parameter variables inside the functions. Allow me to demonstrate:

 peterbe@trillian:~ $ python slimmer.py --hardcore --test plone.js 
 Took 1.887 seconds
 Bytes before: 92739
 Bytes after:  47593
 Bytes after zlib: 15081
 Bytes saved:  45146 (44K)  (51.0% of original size)

 peterbe@trillian:~ $ python slimmer.py --test plone.js 
 Took 0.467 seconds
 Bytes before: 92739
 Bytes after:  51088
 Bytes after zlib: 15179
 Bytes saved:  41651 (40K)  (55.0% of original size)

It's not a huge improvement with these new "hardcore techniques" but it at least works.



Comment

Show all 1 comments
 
Name:
Email:
hide my email address.

Your email address will be encoded to prevent email-extraction spiders from reading it so you won't get spammed if you decide to show your email address.