• Hi,

    I don't have much time today, but just some things I've seen quickly:

    • if (resource.file){ result.buffer = E.toArrayBuffer(atob(require("Storage").­read(resource.file))); - you should really store the image as binary - so write what's in the file with atob in the write call, so that when you read you don't have to call atob and it's not having to read the whole image into RAM and then convert base64. it'll take up less space too.
    • Same with compressed - in most cases it's going to be far faster to just read the image uncompressed I imagine since you're not having to load the whole thing into RAM

    I'd mentioned above about it being so much better to use your customiser app to just put all the draw calls together rather than using switch statements. What you're doing right now is making an interpreter (for your JSON files) inside the Espruino JS interpreter - so cycles are being thrown away.

    So instead of:

    for (var current in element){
        // ...
            switch(current){
              //...
              case "MultiState":
                drawMultiState(currentElement, elementOffset);
                break;
              case "Image":
                drawImage(currentElement, elementOffset);
                break;
              case "CodedImage":
                drawCodedImage(currentElement, elementOffset);
                break;
              case "Number":
                drawNumber(currentElement, elementOffset);
                break;
              case "Poly":
                drawPoly(currentElement, elementOffset);
                break;
              case "Scale":
                drawScale(currentElement, elementOffset);
    

    Do that inside your customiser and instead just write JS directly that looks like:

    drawCodedImage(element[0], elementOffset);
    drawMultiState(element[1], elementOffset);
    drawPoly(element[2], elementOffset);
    

    You could even do that in JS inside the app so your customiser doesn't have to change (create a set of draw commands in a string and then 'eval' it)

    Worth looking at http://www.espruino.com/Performance but Espruino executes the JS from source. That means that if you have a switch statement it's having to parse through all the code every time it handles the switch - so yes, it'll be slow.

    You could see how we handle it in the Layout library to run through things quick - add the functions to an object, and then just index that object to find the right function to run: https://github.com/espruino/BangleApps/b­lob/master/modules/Layout.js#L346-L396

    But really it's much better to avoid that completely if you can.

About

Avatar for Gordon @Gordon started