lua-users home
lua-l archive

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


On Wed, 17 Dec 2014 13:58:10 -0800
Tim Hill <drtimhill@gmail.com> wrote:

> luaL_openlibs() is (comparatively) expensive; on our reference system
> we can create a new raw Lua state in approx. 4us, but setting up the
> libraries takes about 250us. In reality if you are doing this only
> every 100ms then perhaps that is not too much overhead, however this
> depends on the speed of your platform (our reference system is a core
> i7 2.6GHz cpu). In addition, be aware that Lua does a “clean” close,
> and runs a garbage collect at close time, which can also take time
> depending on how much memory is to be collected.
> 
> Keeping an open Lua state would be much faster, but of course your
> scripts need to be aware that they will inherit the outgoing global
> state of the previous script. There are also a number of techniques
> to avoid this, such as maintaining a shadow Lua global state that can
> be reset at the end of the script. You might also consider if you
> should do a manual garbage collect after each run of the script to
> keep memory overhead low, if this is an issue for you.

Thank you. My platform will be an embedded system, so I do care about time. My
target CPU is a Cortex-A7 at 1GHz.

I tested the memory allocation with valgrind, and it seems there is no extra
memory allocated after each run. If there's any other tool that can detect
such leak, please let me know.

Thanks,
Levente