You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Hi - this looks like a fun project!

    The first (and really big) thing I see is actually this:

    this.appFunctions = eval(appCode + `; return [start, loop];`);

    This may seem really innocent - but if you could ensure appCode is a string loaded directly using require("Storage").read, but with ; return [start, loop]; already in it, then you eval it directly, you'll find your RAM usage is drastically lower.

    For instance:

    var appCode = require("Storage").read(appName);
    this.appFunctions = eval(appCode);

    Why? If you eval a string and that string is a string that's in flash memory, Espruino doesn't load any of the functions in that string into RAM - the function code stays in flash memory and is executed direct from there.

    However when you add the text ; return [start, loop]; onto the string, the whole thing has to be loaded into RAM first, and now all the function code stays in RAM.

    So I think that one change will likely fix the majority of your problems, but it's also worth looking at some of the suggestions for writing code on Espruino:

    Specifically the stuff about big blobs of data. Basically when you define stuff inside a function, it then doesn't take up any RAM until that function is executed - it just sits in Flash.

    I'm afraid you can't increase Pixl.js's RAM (I don't believe the other Bluetooth modules are pin compatible), but you could add external flash storage (even in the form of an SD card) to store the apps if you wanted.

    Having said that I'm looking into making a Pixl.js v2 with the nRF52840 that'll have bags more RAM and a few extra features (I have a prototype PCB by my side right now) so when those go into production you'd be able to run your code on them (probably with no changes at all) and take advantage of the extra flash and RAM you get


Avatar for Gordon @Gordon started