Lua memory saving tips

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua memory saving tips

Brett Bibby
Hi,
We're developing a console game that uses Lua and wanted to find out any
memory saving tips people might have.

Currently Lua uses more memory than we would like (close to 5MB). When I
looked into the memory allocations incurred by Lua, I was surprised at the
volume. We have over 40,000 allocations. I created a test project to load a
single script with no code inside.

This caused the following allocations:

72 bytes by LoadFunction > luaF_newproto
32 bytes by LoadString (seems to be the name of the file? in this case
"Boot")
21 bytes by LoadString > luaS_newlstr (seems to be the name of the script?
in this case also "Boot")
4 bytes by LoadLines
4 bytes by LoadCode
24 bytes by luaF_newLclosure

Is this correct? Is there a way to suppress things like the line number,
etc.?

Once I start putting code inside the scripts, I see a similar pattern of
allocations for each line of code (or couple of lines of code? not sure what
causes more memory to be allocated). Any tips to help reduce the runtime
memory would be appreciated.

Thanks,
Brett

Reply | Threaded
Open this post in threaded view
|

Re: Lua memory saving tips

Luiz Henrique de Figueiredo
> 72 bytes by LoadFunction > luaF_newproto
> 32 bytes by LoadString (seems to be the name of the file? in this case
> "Boot")
> 21 bytes by LoadString > luaS_newlstr (seems to be the name of the script?
> in this case also "Boot")
> 4 bytes by LoadLines
> 4 bytes by LoadCode
> 24 bytes by luaF_newLclosure
>
> Is this correct? Is there a way to suppress things like the line number,
> etc.?

You seem to be loading precompiled programs. In that case, use "luac -s"
to strip debug information.
--lhf