• Out of resource memory --> RAM.

    I have a GPS, I2C LCD 4x20, two I2C DS3231/2 RTCs and the 1800 memory units will not cut it with my New-Bee javascript user application code.

    Is there a checkoff list that provides knowledgeable suggestions on how to reduce memory RAM usage to the bare minimum? Since I don't know the internal workings of the Espruino any help is appreciated.

  • Well - first there's this: http://www.espruino.com/Performance

    The biggest culprits usually are:
    Simple arrays being used to store numbers. Use a typed array, a string, or anything other than a simple array.
    Code size. Use the minifier in the IDE.

    Also there's some good news on the horizon, and some good news in the present.

    Present: The Espruino Board, despite the spec of the chips saying it only has 48k of ram, seems to have 64k (and 512k flash, too). This gets you 2600 jsvars. I autobuild them nightly and they get posted here: http://drazzy.com/espruino/bigram

    Future: http://forum.espruino.com/conversations/­1615/newest/
    3250 jsvars with bigram (2250 with normal builds), and packed arrays to make simple arrays filled with numbers a little less painful.

  • As @DrAzzy says really - it's really easy to fill up available memory if you use normal arrays. Using stuff like Uint8Array, data goes quite a long way though.

    Also if you're adding comments, try and add those outside the functions as then they don't get stored in Espruino.

  • I removed my GPS user code (to save code space for this testing) and did the following testing below:

    Summary:
    @Gordon Removing "all" text/comments from user code saved 149 in memory usage.

    @DrAzzy - fiddling with optimizations produced very mixed results.
    Optimization #5 reduced memory usage but gave minification errors?
    It looks like more work is needed in the optimizations for the Espruino?
    Note: I did not try "all" combinations optimizations.

    More work is needed in increasing my user application memory usage ...

    Comment removal Testing

    1 Removed all comments from user application code
    Default: Settings/communications Minification: No minification & Module Minification: Whitespace only (default?)
    memory usage before: 1033
    memory usage after: 884
    savings: 149 <-------

    Error window block: None

    Optimization Testing

    2 Optimations combinations with no text in user code.
    Minification: Whitespace Only
    Module minification: Whitespace Only (Default?)

    memory usage before: 884
    memory usage after: 884
    savings: 0 - because of errors?

    Error window block ... Errors while minifying - sending unmodified code <-------

    3 Optimations combinations with no text in user code.
    Minification: Simple Optimizations
    Module minification: Whitespace Only (Default?)

    memory usage before: 884
    memory usage after: 884
    savings: 0 - because of errors?

    Error window block ... Errors while minifying - sending unmodified code <-------

    4 Optimations combinations with no text in user code.
    Minification: Advanced Optimizations (not recommended)
    Module minification: Whitespace Only (Default?)

    memory usage before: 884
    memory usage after: 884
    savings: 0 - because of errors?

    Error window block ... Errors while minifying - sending unmodified code <-------

    5 Optimations combinations with no text in user code.
    Minification: Simple Optimizations
    Module minification: Simple Optimizations

    memory usage before: 884
    memory usage after: 811
    savings: 73 - with errors <---------???? code reduction with errors?

    Error window block ... Errors while minifying - sending unmodified code <-------

    6 Optimations combinations with no text in user code.
    Minification: No minification
    Module minification: No minification

    memory usage before: 884
    memory usage after: 958
    savings: -74 (gain)

    Error window block: None

  • Unless you're loading your own modules, the IDE will by default use minified versions to begin with ( http://espruino.com/modules - those .min.js files ), so module optimization shouldn't matter.

    Are there any bizarre bits of syntax in the code you're sending that might be confusing the minifier? I've only seen minification problems when my code has syntax errors (the minifier will choke on them, but sometimes they won't immediately get flagged up by Espruino)

    I've never had any luck with Advanced Optimizations - it usually produces code that doesn't work (presumably that's why it's 'not recommended')

  • 'Module minification' won't be an issue for you - it only applies to modules loaded with require(...) if they weren't loaded from the Espruino site (in which case they'd be minified already).

    The errors will be because the code you're minifying has some problem which means that the minifier can't handle it. I thought it should have told you what the errors were, but you could paste it into http://closure-compiler.appspot.com/home­ and see what it says.

    Do you have any large-ish arrays in your code? I would have thought this was actually most likely to be the problem...

  • ahh... beaten to it :)

    Yes, Advanced Optimisations are what's produced by the closure compiler in its 'advanced' mode. Problem is they tend to think that they can rename absolutely everything, which breaks a lot. I think someone could potentially write a configuration for it which explained which things it's not allowed to rename, but I haven't had time to look into it properly.

  • The errors will be because the code you're minifying has some problem
    which means that the minifier can't handle it. I thought it should
    have told you what the errors were, but you could paste it into
    closure-compiler.appspot.com/home and see what it says.

    Hmmm ... The Espruino won't optimize/minimize if there is an "unknown" error/warning?
    An on-line Espruino javascript closure compiler -an Espruino double check - very cool indeed.

    I took the "LED test delay code snippet" out from the init() startup code.
    Now I can simple optimize/whitespace (not advanced due to ?) ...

    digitalWrite([LED1,LED2,LED3],0b100);
    setTimeout("digitalWrite([LED1,LED2,LED3­],0b010);", 1000);
    setTimeout("digitalWrite([LED1,LED2,LED3­],0b001);", 2000);
    setTimeout("digitalWrite([LED1,LED2,LED3­],0);", 3000);

    From the on-line JS closure compiler warning ...
    "simple"
    JSC_PARSE_ERROR: Parse error. Binary integer literals are not supported in this language mode. at line 60 character 30
    digitalWrite([LED1,LED2,LED3],0b100);

    BTW ... going from 1800 jsvars to 3250 jsvars using DrAzzy's bigram provides a much needed breathing room for code development. Thanks DrAzzy
    Update ... bigram and my application don't agree with each other?

  • The minimisation is performed by the closure compiler, Espruino Web IDE just sends the data over to it.

    The binary literals are ES6 and aren't supported by the minimizer... but when the web ide minimises it usually replaces them for you. I guess it doesn't do it because they are in a string - I'm just surprised that the minimizer picks it up...

    What errors do you get with bigram? The new ones will include the new changes for memory usage (hence the larger than normal increase in variables).

    I'm still trying to ensure that the new changes work correctly before I make a 'proper' release - so any feedback you have about what is now not working would be hugely helpful.

  • I just tried creating an error in the code in the Web IDE and minifying it - and errors do seem to be reported - like in the image below.

    I think I've found the problem though - it seems there's a bug in how the Web IDE replaces binary numbers in strings which is causing the minifier to fail without errors. I'll see what I can do to fix it...


    1 Attachment

    • Screenshot from 2014-08-05 08:58:44.png
  • Ok, this will be fixed in the next update of the Web IDE that I do (or you can grab the latest from GitHub if you can't wait ). For now, just change your code to:

    digitalWrite([LED1,LED2,LED3],4);
    setTimeout("digitalWrite([LED1,LED2,LED3­],2);", 1000);
    setTimeout("digitalWrite([LED1,LED2,LED3­],1);", 2000);
    setTimeout("digitalWrite([LED1,LED2,LED3­],0);", 3000);
    
  • I just tried creating an error in the code in the Web IDE and
    minifying it - and errors do seem to be reported - like in the image
    below.

    Me too, but using "simple optimizations" on user code, the minimization error blocks flash too quickly and disappear in order. My eyes are not that quick to memorize all the errors. Is there some way to lock or hold the error blocks on screen so I can review the errors?

    Windows 8.1 64 Bit
    Chrome 35.0.1916.153 m (no beta)
    Espruino 1v70 2250 jsvars
    Web-IDE v 45
    Board: Espruino v 1.3

  • I'm afraid there isn't right now... A new Web IDE should automatically download itself in the next hour or so, and that will at least have the binary number problem solved for you.

    As a start, I'd suggest that you make sure there are no areas highlighted as possible problems in the Espruino editor itself.

  • I'm afraid there isn't right now

    Workaround ... very fast use the key "prt sc" (print screen) and then take your time and paste the picture into a doc.

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

New-Bee ... My biggest Espruino fear is coming true!

Posted by Avatar for user7114 @user7114

Actions