[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Table cache
- From: "Brian Weed" <brianw@...>
- Date: Thu, 30 Jul 2009 10:50:57 -0700
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.
[mailto:firstname.lastname@example.org] 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 <email@example.com>:
> The problem I'm trying to solve is that the programmers on this
> written lots of code that is constantly creating way too many
> objects, which bogs down the memory manager (causes low frame rates,
> 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
> to modify all the places that cause this.
> I'm thinking that maybe this can't be done. Perhaps there would be
> 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
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.