lua-users home
lua-l archive

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


Well, the tables would not be re-tasked for different object types
(vectors would stay vectors, etc...), and re-setting x, y, z to 0 is
much less expensive then deleting and then allocating a new table.

Either way, I don't have high hopes about solving this automatically.
I'm thinking that I just need to get my programmers to not create
thousands of temporary tables per frame.

Brian

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Jerome Vuarand
Sent: Thursday, July 30, 2009 10:38 AM
To: Lua list
Subject: Re: Table cache

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.