Memory use #4065
Replies: 1 comment
-
Posted at 2014-08-27 by @gfwilliams Hi, I'll just answer in order:
Posted at 2014-08-27 by @gfwilliams By the way, 1v70 will be much more memory efficient when it comes out Posted at 2014-08-27 by Uhv Sorry, I've not fully understood...
Posted at 2014-08-27 by @gfwilliams Code and data use the same memory so there is no need to reallocate. If you load a module but keep a reference to something it provides, that may stop any memory being freed. Yes, the hy is an f103 board. However if you connected via the 'serial' usb connector you could have problems, as well as if you turned on 'advanced minification' Posted at 2014-08-27 by Uhv Mmm, you speak that the memory is common for data and program. But the 'process.memory()' tells me that there are always 2000 words (4K) allocated for data regardless of code length. STM32VET6 has 64K SRAM, but I can have variables that take up only 4K... It's not very well. I use modules often inside the subroutines in local variables (for example, var a = requires("aaa")), and I beleave, that, when the programm leave the subroutine, the memory for 'a' is released automatically, isn't it? But I've understood so, that in this case it release only the reference to cache, and after leaving of function I must remove the cache. Is it true? Yes, I use an usb connection by VCP. Is that a reason? And what can I do with this? Posted at 2014-08-27 by DrAzzy 2000 jsvars is 40k, not 4k. 20 bytes per jsvar. V70 and later uses 16 bytes per jsvar. On Espruino v69, with the bigram hack on the offical board, you get 2600 jsvars from 64k - 52k for the jsvars, and the rest is used for the stack and JS interpreter. I'm not sure why your board has 64k of ram, but is only being built with 2000 jsvars - I'd expect you could get 2600 with v69 and 3250 with v70, unless there's something different about that chip. Posted at 2014-08-27 by Uhv Is JS interpreter allocated not in flash? What is the Espruino's bin? Is it not a JS interpreter? Any way the RAM is not enough catastrophically... Seems the way out is to save temporarly unusable variables to SD-card. Will 'advanced minification' work ever properly? And when will the v70 be to probe? ;-) Posted at 2014-08-27 by DrAzzy My understanding is that most of the JS interpreter is in the flash, but it still needs that ~12k for itself and the stack. And yeah, I've been constantly up against the RAM limit on my serious Espruino projects. My desk lamp controller uses over 2100 jsvars, plus for some operations, it needs another 100-200 - and I haven't even started work on integrating the nixie tube display (largely since I haven't finished building it - it's over an hour of soldering per digit)... You can also minify your code with one of the widely available javascript minifiers - I was doing that before minification was working correctly for me (simple minification is now working 100% for me - though it won't minify anything if there are any syntax errors.) It seems that the biggest drain on memory is code itself - this is where all my space is going, at least. One of the problems is that the language was designed for general purpose computers with oodles of ram, relative to the size of the code. So there's stuff like String.fromCharCode(), and all the other common builtin functions and libraries have long human readable names. Also, long global variable names (which don't get renamed) can be a killer if you refer to the variable a lot. At least now (if you do a build yourself, at least) you can get 2800 jsvars and the E.getSizeOf() that's in github right now, which should help. Not sure why you only get 2800 jsvars - but that's what the board file says it gets - i'd think it could get 3250 with 64k ram. Gordon has talked about offering a higher-memory version of the Espruino (there are pin-compatible chips with more ram), though I think he said he's doing the Espruino mini first (with 64k ram (ie, should be 3250 jsvars), lower price, and not as many IO pins). I've also considered making modified versions of modules that strip out functionality I don't want. I'd like to make a PHP page to do the snipping automatically, so you could require() the url, passing the module name and functions to exclude, and the page would fetch the module, split it into functions, excise the specified functions, and return the result, which the WebIDE would then send to the Espruino. You can also use an EEPROM to get more read/writeable memory, though it's certainly less convenient. That was what I had in mind when I wrote the module to interface with them. Posted at 2014-08-29 by @gfwilliams @drazzy is right about the amount of variables. If you compile your own images it may be possible to increase the amount of available variables. Previously there were issues with those boards when more variables that were used in them, but that may have been due to problems with the use of FSMC for LCDs. That's all done in software now so it may no longer be an issue.
There was another question about it on here as well. It depends if anyone contributes the needed code - the closure compiler needs a description of every function that is provided by Espruino in order for it to reliably 'advanced minify' the code. Judging by the response in another thread on here it may be that the 'advanced' option disappears, and some offline minifier gets used instead.
Next week or possibly the week after. Of course there's always https://espruino-nightly.noda.se/ if you can't wait. Posted at 2014-09-01 by Uhv Ok. I'm testing it. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-08-27 by Uhv
Dear Gordon, couldn't you answer to some questions about memory use.
Beta Was this translation helpful? Give feedback.
All reactions