Chaiscript memory usage


#1

Do you have any benchmarks on memory usage? I would like to know if Chaiscript can be used in an embedded system on a microcontroller, something like a Cortex M4F.


#2

I do not, but I can give you some information about how ChaiScript operates.

First off, ChaiScript uses about 5MB to launch, which might already be too much for your platform.

After that, ChaiScript is not garbage collected. It’s memory model is stack based. When a variable goes out of scope it is predictably destroyed at that moment.

So, you are pretty much guaranteed that memory is not going to grow beyond your actual runtime usage.

I know that some users have proved ChaiScript on iOS, so I would expect it to work for your usage also. The key will be the same as for any other application with ChaiScript - you’re going to get the best performance (both memory and CPU) in C++. And it’s crazy easy to expose your C++ functions to ChaiScript - so do all of your heavy lifting where you need predictable performance in C++.


#3

Thanks for the information. Unfortunately the most RAM you can get on an M4 is about 300K :frowning:


#4

I think ChaiScript code could be optimized to reduce a lot it’s memory print, but maybe not to 300k ^^;
That would be quite an impressive achievement though. Isn’t Lua working with less than that?


#5

Yes, I’ve given virtually no thought to reducing the memory footprint. The main place right now is probably in Type_Info object. Currently a full byte is used for several attributes which could be changed to a bitset or bit fields. I’ve played with it a little bit, but am a little worried about slowing it down.

-Jason


#6

Is the memory footprint primarily code or data? The part has up to 2 MB of flash for code. I may look at Squirrel as I know it’s running on embedded systems but I am intrigued by Chaiscript as a language.


#7

ChaiScript, Lua, Falcon, Squirel, AngelScript etc can all run on embedded systems (lua is used in NintendoDS games for example) as long as you can use C++ or C on that target and there is enough memory for an instance of the language’s VM, so it depends.
As Jason said the focus on ChaiScript dev so far was not this kind of optimization but from staring at the code it seems like several pass of optimizations would probably reduce drastically it’s overall memory cost (still depending on the scripts content of course).

I believe several things could be done to reduce both code and memory footprint. However I lack time to test them for the moment, but I intend to help soon with optimizations and some features.


#8

I should have been more specific and stated that I know that Squirrel is running a Cortex M3 in particular.