lua-users home
lua-l archive

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



On 25-Jan-07, at 3:19 PM, Matthew Armstrong wrote:

Is there any significant performance overhead when running in protected mode?


No. Setting up the pcall requires one call to setjmp() which creates a jump buffer; essentially a snapshot of all the registers and other bits of state. Once that's done, execution is normal.

Experiments in C have convinced me that setjmp/longjmp exception handling is quite reasonable, and often outperforms c++ exceptions. However, you don't want to do it on every call (both for efficiency and logic reasons). Put pcall's only in places where you can do something about an exceptional condition; if all you're going to do is log the error and terminate the computation, for example, you only need one outermost pcall.