lua-users home
lua-l archive

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

On Sat, 21 Nov 2009 12:19:09 +0100
Florian Weimer <> wrote:

> > Is there any tangible notion of what is to become of newproxy() ?
> >
> > I found it useful today, to add some implicit finalization to
> > objects implemented with tables. (After feeling surprised that
> > '__gc' is for userdata only.)
> __gc is called asynchronously at rather unpredictable points in the
> program.  A C extension writer can take that into account (and can
> actually do some useful work without invoking the garbage collector),
> but it's more difficult to do this in Lua code.  It's also not
> possible to create a critical section which locks out the garbage
> collector.
> It might be better if there was some sort of __gcqueue metatable slot
> which referred to an array.  When the object becomes unreachable, it
> is added to the __gcqueue array.  Lua functions which interact with
> these objects would process the queue.  This way, the side effect
> would occur at well-defined points in the program.

I have to confess that my usage of newproxy() was a bad idea.

In general, because it's better to do things explicitly rather than
implicitly; and more specifically, because I was doing something that
added unnecessary overhead: calling epoll_handle:del(fd) before
collecting a (wrapped) nixio socket object. (Epoll removes closed
descriptors anyway, so it's a wasted system call.)

Also, (while I'm bearing confessions) I've realized that I was getting
really carried away with metatables. I had pretty much *everything*
wrapped in layers of metatable lookups, and have found that stripping
it all away has given a significant speedup. I'm feeling kind of burned
by OOP indoctrination. Please don't tell Steve Dekorte ;)

--# end diary entry