lua-users home
lua-l archive

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


Robert Raschke wrote:
[...]
I find using a "machine state" Lua table that you can pass around to be pretty ideal.

This means looking stuff up dynamically from the table, which gives you an order of magnitude performance hit. Table lookups are *slow*. Simply moving the program counter from one bytecode address to another is fast. Plus using table lookups means that (assuming I've understood you correctly), the handler for each state needs to be a function, which means you run into the problem of efficiently sharing data between the handlers.

As an example, Clue used to run C code converted to Lua at about 30% of the speed of native when using goto. (With LuaJit.) When I took out the foul hack I was using to patch the bytecode to add the gotos, and started using a state variable and if..then..else chain, the performance dropped by 2/3.

--
David Given
dg@cowlark.com