[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Why can't I do for...in on a table?
- From: Mike Pall <mikelu-0509@...>
- Date: Mon, 12 Sep 2005 17:21:21 +0200
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
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
The time for the table traversal itself vanishes in the other
> (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.]