[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: rapid lifetime based collection of transient user data objects?
- From: Ross Bencina <rossb-lists@...>
- Date: Sat, 29 Oct 2011 13:56:38 +1100
Hello Everyone
I would like to know about available techniques for achieving
eager/rapid collection of short-lived user data in Lua. I'm thinking of
things like scope-based, static-lifetime based GC hinting, or maybe
reference counting.
I notice that there has been discussion in the past, some related to
resource cleanup for exception handling [1] and some related to rapid
temporary resource recycling [2]. My interest is in the latter.
What I have in mind is a vector processing system where "vector objects"
are used with the same syntax used for numbers in lua (infix operators,
functions returning vectors etc). I would like to achieve efficient CPU
data cache usage for large temporary user data objects by reusing the
same objects rather than having a bunch of temporary and intermediate
values polluting the cache until the GC collects them.
Here's an example of the kinds of eager resource deallocation I'm
thinking of:
In an expression such as the following, where a, b, c, d are user data:
a = (b + c) + d;
the subexpression b+c will generate a temporary user data.
1) I would like the (b+c) temporary to be collected/freed/recycled
directly after the temporary's last use.
2) If it can be known that this expression is the last use of either b,
c, and/or d, I would like those objects to also be
collected/freed/recycled at that point.
I understand that this is not how GC usually works but is there some way
to achieve this in Lua without resorting to explicit allocation and
freeing functions?
Given that these user data are number-like and cannot hold references to
other objects, I think one approach might be to use reference counting.
Also at least within expressions, and for objects created and used only
in a single scope, it might be relatively easy to determine their
lifetime using static analysis.
It looks like LuaRC/LuaPlus [3, 4] reference counting system might be
one possible approach. Does that seem like a good fit for what I've
described above? Are there other options or approaches I should know
about? How have other people solved this problem? Are these issues being
considered at all for main-line Lua development or are they considered
out of scope?
Thanks very much,
Ross
[1] Subject: [Patch] Finalization of function objects
http://lua-users.org/lists/lua-l/2008-01/msg00138.html
[2] Lua: Improving deterministic resource cleanup
http://john.neggie.net/2009/lua/resource_finalization
[3] Subject: Re: Reference counting patch for Lua 5.1?
http://lua-users.org/lists/lua-l/2007-04/msg00278.html
[4] http://luaplus.org/