lua-users home
lua-l archive

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


Hi,

Wim Couwenberg wrote:
> Lua 4.0.1: ~7.3 seconds
> Lua 5.0.2: ~15.2 seconds
> Lua 5.1-alpha: ~16.1 seconds

Lua 4 inlines the call to luaH_next() and needs two stack slot
copies.

Lua 5.0/5.1 uses luaD_call() which entails setting up a call frame,
calling the libary function next() which in turn needs several
API calls and finally calls back into the core for luaH_next().
It needs 3 stack slot copies for the call arguments plus one copy
for the results.

Lua 5.1 needs an additional stack slot copy for the extra control
variable.

The time for the table traversal itself vanishes in the other
overhead.

> (compiled with VC6, tested on a 2.6GHz Pentium 4)

Similar results with gcc on a PIII.

No surprises here -- more functionality comes at a price.

Caveat: this is a micro benchmark that measures only one tiny
aspect of the whole implementation. Overall Lua 5 is faster
than Lua 4.

Note that putting the plain table syntax back into Lua 5.1
would not be faster (the call overhead is still there).

The only realistic way to get back the Lua 4 speed is to
add a new syntax (which allows the lexer to distinguish the
two cases) and a new opcode. I'm not sure this pays off
when not doing micro benchmarks.

[That said, I know what to optimize next for LuaJIT. Inlining
luaH_next() should be easy. I'll report back when I'm done.]

Bye,
     Mike