mJS memory capacity

  1. My goal is:
    Determine whether I can install a large number (> 80) of RPC Handlers in mJS.

  2. My actions are:
    Incremental development adding RPC Handlers in init.js

  3. The result I see is:
    On startup I get error messages like this after C initialization. I know that the E:M message indicates that I am running out of memory. So as a test, I remove some of my RPC Handlers, and I can get the system to start without error or E:M message. As I re-introduce RPC Handlers in init.js (as in the indicated log), execution starts and proceeds apparently normally. As I re-introduce all of them, a similar E:M message appears and the system crashes .

[Apr 29 13:46:59.945] ◄Init Start
[Apr 29 13:47:06.583] Saving configuration: no error
[Apr 29 13:47:06.583] minheap: 201976 freeheap: 203512 freefile: 1518550
[Apr 29 13:47:06.680] C Init Done
[Apr 29 13:47:07.942] E:M 37905
[Apr 29 13:47:07.942] Heap summary for capabilities 0x00001800:
[Apr 29 13:47:07.942] At 0x3ffae6e0 len 6432 free 0 allocated 6276 min_free 0
[Apr 29 13:47:07.942] largest_free_block 0 alloc_blocks 31 free_blocks 0 total_blocks 31
[Apr 29 13:47:07.942] At 0x3ffbefa0 len 135264 free 36784 allocated 97060 min_free 3488
[Apr 29 13:47:07.942] largest_free_block 33156 alloc_blocks 341 free_blocks 6 total_blocks 347
[Apr 29 13:47:07.942] At 0x3ffe0440 len 15072 free 15036 allocated 0 min_free 15036
[Apr 29 13:47:07.942] largest_free_block 15036 alloc_blocks 0 free_blocks 1 total_blocks 1
[Apr 29 13:47:07.942] At 0x3ffe4350 len 113840 free 36912 allocated 76888 min_free 36912
[Apr 29 13:47:07.942] largest_free_block 36912 alloc_blocks 1 free_blocks 1 total_blocks 2
[Apr 29 13:47:07.942] Totals:
[Apr 29 13:47:07.942] free 88512 allocated 180440 min_free 55436 largest_free_block 36912
[Apr 29 13:47:07.942] E:M 37777
[Apr 29 13:47:07.942] Heap summary for capabilities 0x00001800:
[Apr 29 13:47:07.942] At 0x3ffae6e0 len 6432 free 0 allocated 6276 min_free 0
[Apr 29 13:47:07.942] largest_free_block 0 alloc_blocks 31 free_blocks 0 total_blocks 31
[Apr 29 13:47:07.942] At 0x3ffbefa0 len 135264 free 36784 allocated 97060 min_free 3488
[Apr 29 13:47:07.942] largest_free_block 33156 alloc_blocks 341 free_blocks 6 total_blocks 347
[Apr 29 13:47:07.942] At 0x3ffe0440 len 15072 free 15036 allocated 0 min_free 15036
[Apr 29 13:47:07.942] largest_free_block 15036 alloc_blocks 0 free_blocks 1 total_blocks 1
[Apr 29 13:47:07.942] At 0x3ffe4350 len 113840 free 36912 allocated 76888 min_free 36912
[Apr 29 13:47:07.942] largest_free_block 36912 alloc_blocks 1 free_blocks 1 total_blocks 2
[Apr 29 13:47:07.942] Totals:
[Apr 29 13:47:07.942] free 88512 allocated 180440 min_free 55436 largest_free_block 36912
[Apr 29 13:47:08.395] js start before anything else
[Apr 29 13:47:09.735] js functions done
[Apr 29 13:47:10.163] js RPCs done
[Apr 29 13:47:10.278] ←[0;32mI (61547) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x2def4 (188148) map←[0m
[Apr 29 13:47:10.397] ←[0;32mI (61647) esp_image: segment 1: paddr=0x0003df1c vaddr=0x3ffb0000 size=0x020fc ( 8444) ←[0m
[Apr 29 13:47:10.397] ←[0;32mI (61657) esp_image: segment 2: paddr=0x00040020 vaddr=0x400d0020 size=0xc3d78 (802168) map←[0m
[Apr 29 13:47:10.796] ←[0;32mI (62047) esp_image: segment 3: paddr=0x00103da0 vaddr=0x3ffb20fc size=0x01844 ( 6212) ←[0m
[Apr 29 13:47:10.796] ←[0;32mI (62067) esp_image: segment 4: paddr=0x001055ec vaddr=0x40080000 size=0x1ad04 (109828) ←[0m
[Apr 29 13:47:10.867] ←[0;32mI (62127) esp_image: segment 5: paddr=0x001202f8 vaddr=0x400c0000 size=0x00034 ( 52) ←[0m
[Apr 29 13:47:10.867] ←[0;32mI (62137) esp_ota_ops: New OTA data 1: seq 0x00000053, st 0x10, CRC 0xe4240fdc←[0m
[Apr 29 13:47:11.146] tUp: 61 now: 5887 mDP: 675 Peak: 0.10 Up: 100 DD: 3 dK: 25000.0 FPM: 825 ASet: 0.00 ASpeed: 0.00 SPnt: 0 TPnt: 0.00 ZPnt: 0.00 Angle: 0.00 Turbs: 333 SN: RS7017 V: 516

  1. My expectation & question is:
    What are the memory limitations in mJS?
    What can I do to optimize memory usage in mJS?
    Is there an example of an RPC Handler installation in C?

Thanks for your help?

JSW

There are no intrinsic memory limits in the interpreter, you alloc until you exhaust the heap and you push until you get a stack error. All that depends on how you write code and the amount of libraries you load and keep running.

That looks a bit small to keep a system like this running stable, and you seem to be using OTA

Here

Thanks for the direction. I moved about half of the js RPCs into main.c With no other logic change, the heap space now looks like this:

[May 10 13:05:22.211] tUp: 7216 now: 1683749121 MinHeap: 49048 FreeHeap: 119028

which is probably good enough. The large difference leads me to believe that for certain operations (RPC installation as a perfect example), mJS is less memory efficient than C. Are there other operations that are better off coded in C?

Thanks,

JSW

Can’t help with this, I only use C/C++, no mJS…

“There is no such thing as a free lunch”
If you want to have a higher level interpreted script language you will have to sacrifice memory footprint, execution speed, or both. If you want a cheap micro with low memory capacity you’ll have to work extra to make your application fit.
Do your analysis, architect your design, choose your tools, do your work