• @Gordon

    I'd imagine that your example of using var htu = exports.connect( null ); may cause some problems though. ...

    Extern/usage files are handled differently by the optimizer. It's enough to reference the functions. First I thought a usage scenario is better readable but it's not.

    htu.isMeasuring;
    htu.readTemperature;
    htu.getTemperature;
    htu.readHumidity;
    htu.getHumidity;
    htu.getCompensatedHumidity;
    htu.getDewPoint;
    htu.softReset;
    htu.getResolution;
    htu.setResolution;
    htu.isEndOfBattery;
    htu.isHeaterOn;
    htu.setHeaterOn;
    htu.getSerialNumer;
    

    Also, when the modules themselves are minified, they get wrapped with (function() { ... })(), which allows the compiler to rename any non-exported functions/variables, even with simple optimisations.

    I saw the wrapping in the build script. It's not nessecarry in advance mode anymore. It's even counterproductive. After wrapping, minifying and unwrapping the HTU21D module is a few bytes larger (in advanced mode). I will investigate it when the next steps are clear.

    Is that what you're doing for your figures here? Last I checked, the difference in size was nowhere near as big as you're getting - there does seem to be a difference between the modules at espruino.com/modules/ and the figures you have...

    I didn't try to cheat. I found that the difference between the current minified files on the website and my numbers in the posting was in the compiler settings and the (sometimes) missing wrapping in my build settings.
    And I tricked myself: The minified version is even smaller, e.g. MCP9808:

    • Earlier posting: simple minified: 3745 bytes
    • Earlier posting: advanced minified: 2427 bytes
    • Website: 3429 bytes
    • Now minified with advanced optimization: 1994 bytes (> 40% smaller)

    I'm not quite sure how that'd be done, but it might be that just defining require as function require(x) { return modules[x]; } would be enough - the closure compiler is pretty smart.

    I will try and report back. But it will take a few days. And without ensuring that every used module is "advanced optimization"-safe we cannot enabled advance optimization for whole programs.

    What should be the next step? Perhaps selecting one module as an example, specify the exact steps, writing the extern file, customizing the build script, ...?

About

Avatar for luwar @luwar started