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:
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.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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 withatob
in the write call, so that when you read you don't have to callatob
and it's not having to read the whole image into RAM and then convert base64. it'll take up less space too.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:
Do that inside your customiser and instead just write JS directly that looks like:
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/blob/master/modules/Layout.js#L346-L396
But really it's much better to avoid that completely if you can.