Minification problems

Posted on
  • Continuation of: original post

    In custom.html, merge all of imageclock.draw.js into imageclock.app.js - and then it'll all get minified together and should end up faster.

    I tried this and got 5-10% faster time to first complete draw by pretokenization alone. Additionally using minification got about 5% on top of that. So pretty worthwhile I think.

    for (let a of a.getPoints())
    It looks like a minifier bug? a = [3,4,5]; for (let a of a) console.log(a); fails in Node.js too so it's not a problem with Espruino not being spec compliant.

    That could well be. I could not find similar problem descriptions, but redeclaring a variable existing in an outside scope sure seems fishy.
    Edit: I have tried running the closure compiler on the same code and it creates for (var n of a.getPoints()) instead

    the minifier generated a constant named g into a block of code calling Bangle.load which in turn calls g.reset()
    That feels like another minifier bug?

    I don't know. Does the minifier actually know that Bangle.load can call g.whatever()? This is probably a quite seldom problem, since you need to have code using enough variables that the minifier gets to "g" as a variable name. Maybe it would be enough to prohibit the minifier from using "g" as a name?

  • redeclaring a variable existing in an outside scope sure seems fishy.

    Yes... The problem I have is esprima seems more or less unmaintained now - and it's hard to find a decent minifier that can be bundled up and run in the browser and node.js.

    Someone attempted using rollup at one point. but as I remember it was huge and ended up being a bit of a mess to use.

    Does the minifier actually know that Bangle.load can call g.whatever()?

    Oh, I misunderstood.

    That shouldn't actually be a problem. Or was it generating a new global variable of that name?

    If you do:

    function boom() {
      g.reset();
    }
    
    function hello() {
      var g = "blah";
      boom();
    }
    

    or:

    function boom() {
      g.reset();
    }
    
    {
      let g = "blah";
      boom();
    }
    

    Then there should be no problem - the function that uses g will only do it from the global scope, not the local one

  • Regarding another minifier than esprima, have you tried uglifyjs? It is build for Node.js and there are projects using it wrapped for a browser like https://github.com/Skalman/UglifyJS-onliĀ­ne. I know close to nothing about the whole NPM/Node world, it's just what I had seen used for minification sometime before.

    As for the minification problem in iconlaunch, I currently can not reproduce that because of changes I have done to iconlaunch since then. Probably because the problematic code now just uses other variable names after minification. I will have an eye on that and try to build a minimum sample if I see it happening again.

  • I can't remember exactly... but it looks from the commit history like we never put uglifyjs in publicly - so may it's an option...

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Minification problems

Posted by Avatar for halemmerich @halemmerich

Actions