lua-users home
lua-l archive

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


2009/7/27 Brian Weed <brianw@imaginengine.com>:
> The problem I’m trying to solve is that the programmers on this project have
> written lots of code that is constantly creating way too many temporary
> objects, which bogs down the memory manager (causes low frame rates, and
> choppiness).
>
> I would like to solve this problem automatically in one spot, at all
> possible (auto cache these objects, and reuse them), so that we don’t have
> to modify all the places that cause this.
>
> I’m thinking that maybe this can’t be done.  Perhaps there would be too many
> side effects to resurrecting the object.

If you want to reuse tables, I guess you want to clean them before
reuse. In the end you will spend more CPU cycles cleaning table than
just allocating new ones and let the garbage collector be smart. Lua
5.1 has an incremental garbage collector, you should tweak it a bit to
improve your framerate.

If you really believe than cleaning tables is cheaper than allocating
new ones, you should search the mailing list archive for previous
attempts at doing so, and see how it ended (I don't remember the final
result, since I'm not interested in the topic, but I remember it was
discussed recently).

You can use the newproxy hack, but it implies creating a userdata and
metatable per pooled object reference. Even with a shared metatable,
each userdata proxy is still more work for the garbage collector.