Garbage Collection In Real Time Games

lua-users home
wiki

Some notes on garbage collection in real-time games, as it relates to Lua. Please correct, extend and update these notes. -- ThatcherUlrich

VersionNotice: Lua 5.1 has got an incremental GC, so many of these points may be of only historical interest.

To maintain low-latency operation, the garbage collector must be allowed to perform a little bit of work on a regular basis. For games, this means the game loop should call the garbage collector once per frame. This is a much coarser level of granularity than what is usually discussed in the literature, where the focus has often been on algorithms for multiprocessors. Johnstone's thesis explicitly addresses the uniprocessor case though.
The write barrier is pretty simple; there are a few variations depending on the exact algorithm, but in the end it amounts to maybe 5 or 10 lines of C, and 10 or 20 instructions.

Implementation note: it would be nice for the Lua implementation to use a macro whereever it writes to an internal (table) pointer (perhaps it already does). Then an add-on incremental collector could define this macro as a function call to the write barrier (or the inline code for the write barrier itself).


RecentChanges · preferences
edit · history
Last edited March 16, 2009 12:14 pm GMT (diff)