lua-users home
lua-l archive

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


Alexander Gladysh wrote:
On Mon, Nov 17, 2008 at 3:38 PM, Peter Cawley <lua@corsix.org> wrote:
It may be worth looking at the generated Lua opcodes for these benchmarks in
order to easier see the differences in what is happening in each. For
example, return true v.s return nil are loadbool,return vs. loadnil,return.
Then looking at the VM code for these operations, either in C or as the
assembled output of the C, might make it clearer. Of course, this won't help
with explaining the luajit results, as it skips the VM when JITing.

Sorry for the late reply.

Opcode listing (via luac -l -l) is indeed very helpful. Chaining calls
use less resources, since they do not require extra MOVE opcodes:

local function chain_local()
  local chain = chain
  chain () () () () () () () () () () -- 10 calls
end
[snip]

Trouble is, does this pattern ever appear in normal code? I find it difficult to believe that calling a function that returns a function to be called, and so on, chained in this manner, could happen in real-world code.

I prefer to accept that the stack setup for the call has to be there, even if it's one MOVE instruction for the closure object. Note that the register holding the closure reference is 'consumed', so in normal usage, we're always going to have at least that MOVE.

Comparing costs of different stack setup patterns might be more useful. I just think that chain()()()()()() is not real-world, and hence, less useful in benchmark comparisons, or even misleading.

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia