lua-users home
lua-l archive

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


The flexibility of Lua means that such "temporary object" optimization is
usually not possible. For instance, consider an immutable tuple operation as
follows:

myVec = vector(2,3,4) + vector(5,6,7)

who knows what the vector __add metamethod's going to do with those instances?
It could hide them away in a global table somewhere. As soon as a reference is
passed into a function--any function--it can't be considered a 'temporary'
anymore. This is both a blessing and a curse, of course. And I would argue
strongly against placing implementation constraints on metamethods... the design
principle that users shouldn't have to care about gc implementation, IMHO, is
very important to Lua.

For an M&S gc, Lua is very efficient at dealing with large numbers of objects.
Of course, incremental gc would be infinitely superior, but I'd suggest that you
do some actual tests on real-world situations before you make assumptions about
performance ("premature optimization", etc.).

Ben

> The problem is, unless
> the garbage collector is very smart its going to have to go through pretty
> much every single object in existance checking its reference count, when a
> few quick checks after an expression would solve the problem.  Going through
> every object at the end of every frame seems to be a major amount of
> overhead.  Of course, the garbage collector might not be as naive as this, I
> haven't analysed that part of Lua yet.