lua-users home
lua-l archive

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


>> Did you benchmark that ?

Yes.

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
frame:

function sprite.foo(self)

    local v = vector(1, 2, 3)

    self.position:AddVector(v)	
end

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.

Brian


-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] 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 <brianw@imaginengine.com>:
> 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 ?