lua-users home
lua-l archive

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


> I (not being aware of how the internals of your co-routines are implemented)
> am wondering why having coroutines now makes general Lua function calls
> slower?

I guess the main reason is that we had to unroll recursive calls (in the
C code) into loops with an explicit stack. Several local variables in
luaV_execute were automatically saved/restored when that function called
itself recursively; now we must save/restore them manually. The internal
C stack is faster than any external stack that we can code (despite some
books trying to convince you otherwise).

Also, the call/return code is a little more complex, because there are
more different cases to handle (e.g. a "return" may be a real C return,
if the function was called from C, or a stack pop, if the function was
called from Lua).

-- Roberto