lua-users home
lua-l archive

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


Currently Lua GC always sweeps all data during cycle, which means that
no short-lived data can be collected more often than it takes GC
to traverse all live data.
Having very large, rarely modified static data set increases length of cycle,
and most of it is spent marking static data that is live and that does not
contain references to new objects. In turn, that increases lifetime of
temporary objects and thus memory usage.
This is typical case where having generational GC should help.
There was something like such thing in the lua-5.1-work4.
Commenting on it's removal, Roberto Ierusalimschy wrote:
 " For some not yet fully understood reasons, its
" behavior was far from what we expected from a real generational collector.
Indeed, on the following code work5 without generational GC is _faster_:
-------------------------------------------
local function g()
    local ret = {}
    for i=1,1000 do ret[i] = {a=1} end
    return ret
end
local b = {}
for i=1,1000 do b[i]=g() end

local t = {}

collectgarbage()
collectgarbage()

local n = 0
for i=1,10000000 do
    local s = "n" .. i
    t[n] = s
    if n == 4 then n = 0 else n = n + 1 end
end

collectgarbage()
collectgarbage()
-------------------------------------------
My questions are whether there are some previous attempts at putting this
back in and making it actually work, how well could it work,
is GC still compatible with such modification and has someone tried, etc.