Page 1 of 1

Is Flash/AS3 faster than Lua?

Posted: Sun May 27, 2012 2:58 am
by _ex_
Hello list,
I was porting my Fractal viewer from Flash/AS3 to Killa (my language based in Lua 5.2) when I noticed a very noticeable slow down in the Love counterpart.

Image

I was incredulous at first and translated the code to Lua to check if it was some problem with Killa but it was the same. I went to test with LuaJIT, it took half of the time but still double than flash to redraw the fractal. I know that the Flash player optimizes the virtual machine code using JIT but I was under the impression that Lua was faster. I'm using Love 0.8 with canvas, I heard they are slow but I was expecting them to be slow as Flash or faster. The flash version can be played here: http://elrinconde-ex.blogspot.com/2012/ ... iewer.html

I'm attaching the love file, if someone can help me to optimize this it would be great, I can be missing something really obvious.

Re: Is Flash/AS3 faster than Lua?

Posted: Sun May 27, 2012 4:33 am
by Xgoff
depends on what you're doing in terms of c calls; currently luajit can't compile c function calls that have been bound with the regular lua c api, which will result in a trace abort: that call and likely a fair bit of other code in that path will run interpreted. if you're drawing pixels individually, then ouch (even if it could compile those, it's still going through the c api which is going to have quite some overhead for setting pixels)

you'd have to use luajit's v and/or dump modules to get a better understanding of what is and isn't being compiled. if love exposes a way to set imagedata based on a table's contents then that might help quite a bit, since that would cut down on a hell of a lot of c calls (this would help the standard lua version a lot too, i'd imagine).

ideally, a luajit version of love would actually be implemented as much as possible in lua, using luajit's ffi for all c calls apart from the standard library (as c calls done through the ffi are at least compilable [except for uncommon variants, maybe])

EDIT: just for shits i v'd it

Code: Select all

[TRACE --- main.lua:143 -- leaving loop in root trace at main.lua:160]
[TRACE --- main.lua:133 -- inner loop in root trace at main.lua:147]
[TRACE --- main.lua:143 -- leaving loop in root trace at main.lua:160]
[TRACE --- main.lua:133 -- NYI: C function 0x02afe0a0 at main.lua:167]
[TRACE --- main.lua:143 -- leaving loop in root trace at main.lua:160]
[TRACE --- main.lua:133 -- NYI: C function 0x02afe0a0 at main.lua:167]
[TRACE --- main.lua:143 -- leaving loop in root trace at main.lua:160]
[TRACE --- main.lua:133 -- NYI: C function 0x02afe0a0 at main.lua:167]
[TRACE --- main.lua:143 -- leaving loop in root trace at main.lua:160]
[TRACE --- main.lua:133 -- NYI: C function 0x02afe0a0 at main.lua:167]
[TRACE --- main.lua:143 -- leaving loop in root trace at main.lua:160]
[TRACE --- main.lua:133 -- NYI: C function 0x02afe0a0 at main.lua:167]
[TRACE --- main.lua:143 -- leaving loop in root trace at main.lua:160]
[TRACE --- main.lua:133 -- NYI: C function 0x02afe0a0 at main.lua:167]
[TRACE --- main.lua:143 -- leaving loop in root trace at main.lua:160]
[TRACE --- main.lua:133 -- NYI: C function 0x02afe0a0 at main.lua:167]
[TRACE --- main.lua:143 -- leaving loop in root trace at main.lua:160]
[TRACE --- main.lua:133 -- NYI: C function 0x02afe0a0 at main.lua:167]
[TRACE --- main.lua:143 -- leaving loop in root trace at main.lua:160]
[TRACE --- main.lua:133 -- NYI: C function 0x02afe0a0 at main.lua:167]
[TRACE --- main.lua:132 -- NYI: C function 0x02afe0a0 at main.lua:167]
[TRACE --- main.lua:143 -- leaving loop in root trace at main.lua:160]
[TRACE --- main.lua:133 -- blacklisted at main.lua:143]
[TRACE --- main.lua:132 -- blacklisted at main.lua:143]
[TRACE --- main.lua:132 -- blacklisted at main.lua:143]
[TRACE --- main.lua:132 -- blacklisted at main.lua:143]
[TRACE --- "boot.lua":387 -- leaving loop in root trace at "boot.lua":401]
[TRACE --- "boot.lua":383 -- NYI: C function 0x02b04218 at "boot.lua":386]
[TRACE --- main.lua:403 -- NYI: C function 0x02b04a88 at main.lua:404]
[TRACE --- "boot.lua":387 -- leaving loop in root trace at "boot.lua":401]
[TRACE --- "boot.lua":383 -- NYI: C function 0x02b04218 at "boot.lua":386]
those NYIs are killers

Re: Is Flash/AS3 faster than Lua?

Posted: Sun May 27, 2012 2:22 pm
by _ex_
Yes, I also think the problem is the constant trespassing of the Lua/C++ barrier to draw every pixel.
To be fair Flash version is using a BitmapData structure (AS3 has bytearray structures) so I'm drawing the pixels directly to the bitmap for later rendering.
I was looking for, but couldn't find something like that in Love. I can be wrong, though.
This seems a nice place to modify Lua, let me check.

Re: Is Flash/AS3 faster than Lua?

Posted: Sun May 27, 2012 3:22 pm
by slime
Why not use a shader?

Re: Is Flash/AS3 faster than Lua?

Posted: Sun May 27, 2012 3:35 pm
by _ex_
slime wrote:Why not use a shader?
to be honest, I don't know where to start to create a mandelbrot fractal shader in Love, it's easy?

Re: Is Flash/AS3 faster than Lua?

Posted: Mon May 28, 2012 11:26 am
by richapple
_ex_ wrote:
slime wrote:Why not use a shader?
to be honest, I don't know where to start to create a mandelbrot fractal shader in Love, it's easy?
You definitely should use a shader:
  1. Löve is hardware accelerated, meaning iterating pixels on the screen isn't it's purpose. There was a thread about found it
  2. Löve is a very easy way to start learning about shaders: a lot of cool examples in this thread
All in all, give it a try

also bonus for all you android users