lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, May 30, 2017 at 12:48 PM, Amit Aryeh Levy <amit@amitlevy.com> wrote:
> Hi all,
>
> I've begun implementing a Lua runtime for very low-memory processes on
> embedded systems
> (https://github.com/helena-project/tock/blob/master/userland/examples/lua-hello/main.c)
>
> So far, with at least a basically naive use of the lua library, memory
> usage is non-trivial for this environment: the base library takes ~8kB
> of heap and requires an additional 2-3kB of stack to parse, compile and
> run a simple hello world. The code size overhead is also reasonably
> large---~90kB. I'm wondering a few things:
>
> 1. It looks like the default LUA_BUFFERSIZE, which seems to be impacting
> max stack size the most, is relatively large---2048 bytes when
> LUA_32BITS is set (or 8192 otherwise). Is it safe to make this smaller?
> If so, by how much and are there any invariants this size must adhere to?
>
> 2. Are there particularly expensive parts of Lua in terms of code size
> that are possible to avoid? For example, it's probably reasonable not to
> support compilation of plaintext Lua code to bytecode on the device and
> instead only run load pre-compiled bytecode, which I can imagine
> reducing code size of the runtime significantly, however, it doesn't
> seem trivial to remove just the ascii parser while keeping the bytecode
> parser.
>
> 3. Are there general resources available for minimizing memory usage in
> Lua? Of course reducing overhead in the runtime would be useful, but I'm
> also interested in guiding how Lua libraries are written. For example,
> it seems as though closures are reasonably expensive and perhaps storing
> them long term should be avoided. Are there programming patterns like
> that which are well understood and documented somehwere?
>
> Thanks!!
> Amit

Have you looked at the elua project?

http://www.eluaproject.net/overview

https://github.com/elua/elua

Probably lots of good stuff in there...

Russ