lua-users home
lua-l archive

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

2014-07-11 4:39 GMT+08:00 Eric Wing <>:
> Although even when not jitting, the hand-coded interpreter is going to
> give that extra factor of 2 or 3 times - *if* the platform is
> supported by LuaJIT.

So I would like to see real numbers on this and document under which
circumstances and try to avoid propaganda because bad information can
encourage bad decisions. I recently did some internal benchmarks of
LuaJIT vs. Lua 5.3 work 2 on an iPad mini (1st gen). The iPad
disallows JIT so LuaJIT must go through the interpreted mode. I saw no
speed difference between the two. (I have heard the claims the
hand-coded interpreter still yielded significant benefits, and I'm
disappointed they didn't live up.)

Repeating the same benchmark on a desktop where LuaJIT can use JIT, I
did see the significant speedup of course.

The experiment was a sprite test with SDL bound to Lua (using
traditional compiled techniques, not FFI). So the two common hot paths
were calling into C (to call SDL drawing APIs) and to actually
compute/move the sprites around. I also wrote a pure C version as a
control. Off the top of my head, I think Lua 5.3 was a little shy of
60% of C. LuaJIT with JIT enabled was 75% of C. (I consider this
pretty good because I expected less since most of the code crosses
into C...I was surprised how much LuaJIT could speed up my simple
sprite movement code.)

By the way, I've also been playing with shrinking Lua 5.3's number
types. On the iPad, I've seen a little short of 10% speed up. (I
really like Lua 5.3 and integer subtypes!)

Beginning iPhone Games Development

I am not expert in this but I also did some crude benchmark back then. If you are benchmarking using a program that actually draws sprites, then I think the bottleneck isn't even the Lua/C API barrier, as it should be actually drawing things on the screen, no? Or that's already been accounted for?

And I think there's no bad information, but there might be people who jump to conclusion too easily and think LuaJIT can boost their program at least 2~3 times faster no matter what they write down in Lua.

Information can simply be obtained by looking at:

As you can see if you switch to Lua v.s. LuaJIT2 interpreter-only benchmark, on x86/64 it's ranging from 1.5x ~ 5.5x, so you would consider generally a 2 ~ 3 times speedup can be expected, if it's pure Lua. However, on ARM it's only 1x ~ 3.5x ... So, if the same experiment on PC already yield only a little improvement, on non-jitted ARM environments the speedup can be nearly non-existent.