lua-users home
lua-l archive

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


Daniel Silverstone wrote:
...
When I last worked on a game engine, we would force a garbage-collect
once per second which was less irritating than every frame but often
enough to keep memory use down. But we weren't using Lua so I don't know
how Lua would behave in this instance.

One of the most incredible things about Lua 5.1 is its incremental GC. We have a rendering engine which uses Lua, so we have a rendering loop that runs at ~60fps. After each loop I added this:

    double ct = getCurrentTime();
    lua_gc(myState, LUA_GCSTEP, 10);
    ct = getCurrentTime() - ct;

The resultant ct (collect time) is close to 0% when the system was at idle and rarely got above 1% of total frame time at high load. I also monitored memory usage:

    int memused = lua_gc(myState, LUA_GCCOUNT, 0);

and found that memory would peak after some high load frames and then take around 2 seconds or so (120 frames) to get back to its quiescent state. This is great for any real-time system like this. Memory usage is kept under control, but GC never affects frame rate and therefore animation stays smooth.

So, switch to 5.1 :-)

--
chris marrin              ,""$, "As a general rule,don't solve puzzles
chris@marrin.com        b`    $  that open portals to Hell" ,,.
        ,.`           ,b`    ,`                            , 1$'
     ,|`             mP    ,`                              :$$'     ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`