lua-users home
lua-l archive

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

>> Did you benchmark that ?


After facing the same problem on another project 3 weeks ago (same game
engine), I changed the game code to re-use a global vector object,
instead of recreating them as local temporary objects.  This was a huge
boost to performance.

The purpose of this thread was to find a way for me to implement that
optimization automatically, because the amount of code affected on this
project is much greater.

Consider the following example which may be called hundreds of times per


    local v = vector(1, 2, 3)


vector() is function that returns a table (that has methods, a
metatable, etc...)

self.position is also a vector.

Creating many temp objects like this is the cause of our performance
problems (according to the profiler).

Now obviously that function could be re-written to be much less
expensive, but unfortunately, that's just one example of hundreds of
places across 156k lines of Lua code.

Perhaps my biggest problem is our memory manager not handling thousands
of small allocations speedily.


-----Original Message-----
[] On Behalf Of Jerome Vuarand
Sent: Friday, July 31, 2009 4:53 AM
To: Lua list
Subject: Re: Table cache

2009/7/30 Brian Weed <>:
> 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.

Did you benchmark that ?