lua-users home
lua-l archive

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


Hi,

One of the difficulties of generating high performance code for Lua in
a _naive_ way is that many op codes have a lot of branching. A simple
add instruction may do:

if (isint(a) && isint(b))
   integer add a, b
else if (isfloat(a) && isfloat(b))
   float add a, b
else if (hasaddmeta(a) || hasaddmeta(b))
   invoke meta add a, b

This is really inefficient when JIT compiled.

Added to this is the need to support coroutines, which can yield in
the middle of a metamethod, so that complicates life further because
after a metamethod call, you cannot assume that the Lua stack is the
same.

So I am thinking of experimenting with a minified Lua - regress back
to 5.1 but on top of that:

* Eliminate metamethods except for __gc.
* No more coroutines

So back to only one number type. As you can imagine this would mean
add can simply be:
a + b

Now, I do not know how often people implement operator overloading -
but given some languages do not have this feature it may not be a big
loss.

I personally can do without coroutines too, I am not sure how widely
they are used; but the trade off is that we eliminate a bunch of
complexity from mini Lua.

I think there are other things I could eliminate such as var args. But
for now, I may start with above. I don't know right now if I should
try to trim down current Ravi code or start with Lua 5.1.

The difficult bit is getting time to do all this.

Regards
Dibyendu