lua-users home
lua-l archive

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


Hi,

Wim Couwenberg wrote:
> On a related note, I wonder if it would be at all possible to optimise 
> tailcalls any further?

Yes. The current code for OP_TAILCALL always adds a new call frame.
When it finds that it was a Lua function, it undoes that by moving
everything one frame down. Doing this in one step requires quite
a bit of code restructuring, though. It should be faster, but I'm
not sure by how much.

If someone wants to take on this: merge/simplify the code from
luaD_precall with the code after OP_TAILCALL in luaV_execute.
But you need to be careful: there are some subtle interactions
with stack slots and call frames for generic callables and for
vararg functions.

> The recursive sumr takes about 2.5 times more time than the iterative 
> sumi in 5.0.2.  (In 5.1-w5 both are quicker, but the iterative version 
> more so than the recursive one...)  If tailcalls get cheaper, they would 
> gain in strength as "structured goto's".

I don't think we can get generic tailcalls that much faster.
Speeding up simple recursive functions is doable with a lot of help
from the compiler (essentially converting the call to a jump).
But this won't help with the structured goto use case where the
target cannot be derived statically (most of the time).

Bye,
     Mike