-
• #2
1 - not sure if "typically" but yes it can run from RAM or from flash. When in ram the parsed string of each function is in RAM (possibly minified and tokenized) as a variable. in javascript there is no big difference between variable referencing integer value, string or function object
if loaded from flash the difference is that function object has pointer to string of the body which is in flash, also plain strings work like that not just functions so if code in flash has
var s = "very long string .. "
than the string is also in flash, not in ram2 it is based on number of variables (=
JSVAR_CACHE_SIZE
) see https://github.com/espruino/Espruino/blob/master/src/jsutils.h#L1953 there is no performance penalty when running from internal flash, there is small one when running from SPI flash (Bangle watches)
the size is defined in board files like this https://github.com/espruino/Espruino/blob/master/boards/PUCKJS.py#L25
the size is basically determined by trial and error - you check how much free RAM you have with everything built in + CPU stack and you divide size of free ram by variable size. For PUCKJS with 2756 variables it needs 35828 bytes of RAM (out of 64KB), the rest is for static C data, CPU stack and bluetooth - NRF softdevice
-
• #3
This one? http://www.espruino.com/Other+Boards
It may be slightly out of date as we've tweaked the amount of available vars recently.
JS typically executes in RAM, so I assume the full size of the JS text is subtracted from available RAM before the rest is allocated to variables?
Espruino will execute JS direct from flash (as long as you save using the IDE and not the
save()
function - see https://www.espruino.com/Saving) so the actual RAM usage of a function is just what's needed for the declaration (~3 vars + 1 per argument).What determines whether a JS variable uses 12 or 16 bytes?
It's the total number of variables the board supports. It's basically address size.
Now, the situation is a bit more complex as some boards use 13/14/15 bytes for variables as they're able to pack the addresses a little more tightly.
What options are there for "maximizing" flash or RAM space? I believe it's possible to execute code from flash, but with a possible performance penalty. Where can I find more information on that?
There's no huge performance penalty for executing from Flash on most boards. There is a bit on Bangle.js because the flash chip is external, but on everything else flash is tightly coupled to the chip so isn't noticeably slower than RAM.
These should help:
http://www.espruino.com/Code+Style#other-suggestions
http://www.espruino.com/Performance
http://www.espruino.com/Internals (to a lesser extent)
Somewhere I recall seeing a table (or similar) of the amount of free flash and RAM available for JS on the various devices, and how many JS variables it would support, but I can't find it now. Can anyone point me to it?
Also a few related questions: