Slimmer with --hardcore

06 May 2006   1 comment   Python

Mind that age!

This blog post is 15 years old! Most likely, its content is outdated. Especially if it's technical.

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);

becomes this:

function _A(z) {
function _B(x, y) {
    return _A(x) + _A(y);
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 --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 --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.



Peter, I don't know about the JavaScript, but I bet you'll get a few funny search engine queries for this page :-)

Your email will never ever be published

Related posts