lua-users home
lua-l archive

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


On Jan 13, 2010, at 11:37 PM, Sean Conner wrote:

> It was thus said that the Great Wesley Smith once stated:
>>> It's not the same, though. Apart from having to reorder my logic to suit
>>> the restrictions of the language, which is always a pain, there's a
>>> performance hit in that shared state has to be accessed via upvalues
>>> rather than locals, which are considerably more expensive --- not just
>>> to access, but also to create individual closures for each state in your
>>> state machine. Say you have a state-machine based parser for network
>>> packets. You have two choices: construct and then discard potentially
>>> hundreds of closures for every packet, or restructure the entire state
>>> machine not to need shared state. One's slow, the other's inconvenient.
>> 
>> 
>> Is that really true?  I'm not sure I buy it.  Why can't you use
>> coroutines with locals and and infinite loop to implement your state
>> machine?  I've done this in many situations and have never had the
>> need for upvalues.

While upvalues are slower than locals, I suspect that a table lookup is slower still.

Mark