lua-users home
lua-l archive

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


On Mar 26, 2002 at 10:51 +0800, paul@theV.net wrote:
> With my GC problem getting really serious (refering to my earlier post)
> and the const patch still not solving my issues, I had to dug into the
> Lua source and make my own incremental patch.
> 
> I implemented thri-color with write barrier, and it seems to become
> stable after a week's debugging... but I still have some worries about
> collection speed falling behind garbage generation speed.
> 
> The current L->GCthreshold v.s. L->blocks does not seem to be a good 
> measurement in calculating the gc cycles to be performed. Sometimes it
> collects too often, and sometimes it fails to catch up with the garbages.
> 
> Also doubling the threshold doesn't seem to be a very good idea in 
> incrememtal GC either, since it isn't truely reflecting how much memory
> is really available. If the collection speed falls behind, I actually
> ended up doubling the threshold again and again until memory-full.
> 
> Would anybody shed some light on the two issues? I'd love to make my
> patch available if I didn't code it too wrong :P

Hey, this is very exciting!

My plan for controlling an incremental collector was going to be an
explicit call from the app, something like:

LUA_API void	  lua_dogcincrement (lua_State* L, int count);

where count would specify the number of objects to mark and/or sweep.
If the app never called lua_dogcincrement() then the collector would
just act like the current non-incremental collector.

For a game, you would just put lua_dogcincrement(gc_count) in the main
loop.  You'd experiment with gc_count to find a value that consumes
less than a couple milliseconds; or, you'd do something like:

     ...
     while (time_until_vblank() > 1.5)	/* time in milliseconds */
     {
	lua_dogcincrement(500);	/* or some other count that always takes < 1 ms */
     }
     swap_buffers();

You get the idea -- put the increment explicitly in the hands of the
app.  If the incremental gc can't keep up, eventually you would get a
blocking gc.

I hope your gc works out!  I'm definitely interested to try it!

-- 
Thatcher Ulrich <tu@tulrich.com>
http://tulrich.com