[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaJIT2 FFI 2D VLA causing massive runtime memory usage growth
- From: Johnson Lin <arch.jslin@...>
- Date: Wed, 23 Feb 2011 17:12:58 +0800
On Wed, Feb 23, 2011 at 6:10 AM, Mike Pall <mikelu-1102@mike.de> wrote:
>> would those two temporaries be the source of this massive growth of
>> memory usage?
>
> Yes, because tmp1 escapes in your example.
>
> Since it's really hard to work around this, I've added a new
> optimization which eliminates escaping temporaries for many cases.
> I've just pushed it to git HEAD -- please try again.
>
>> I just felt these 2 are somehow connected, as they are both
>> FFI-related, and both context used 2D VLA.
>
> Haven't gotten around to run your other example, but it looks like
> it's the same problem. Try again with git HEAD and let me know if
> it still happens.
>
> --Mike
Tons of thanks, Mike!
That did fix both problem (which now turns out to be the same problem).
My SDL/GL Game of Life is too untidy for a good demonstration... It
was intended to be a comparison to a pretty identical version written
in C++ (I wrote LuaJIT FFI [1] version first, and then ported back to
C++ [2]). And I used 4 methods to draw the Life's state onto screen:
direct calls to glVertex3f(s), use Vertex Array, VBO and PBO.
The only case LuaJIT lost to gcc -O3 compiled version was the first
one: glVertex3f calls, since that's one call per cell to a NYI C
function. However when using VA / VBO / PBO, LuaJIT FFI won by 20 ~
33% (!) Only if the memory usage could be lower ... and now that gets
fixed too! Memory usage readings even lower than (at least on par
with) C++ version. (Ok, I admit there's a possibility my C++ skill is
actually crappier than hell.)
Somebody can definitely start to write full blown 3D engines in LuaJIT!
FYI:
[1] https://github.com/archilifelin/mysandbox/blob/master/lua/lifegame_ffi_sdl_gl.lua
[2] https://github.com/archilifelin/mysandbox/tree/master/cpp/lifegame_sdl