Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua - is xpcall as slow as Try...Catch in other languages?

Tags:

lua

I cant seem to find any info about this on the web, but what are the performance implications of using xpcall vs calling a function directly in lua:

a) When there are no errors?

b) When an error occurs?

Is it similar to try... catch from other languages where handling an exception can cause performances issues?

like image 516
Igneous01 Avatar asked Dec 09 '25 17:12

Igneous01


1 Answers

Languages where the cost of exception handling is talked about, like C++, are those which are intended for high performance in the general case, since cleaning up from an exception involves a tricky and expensive stack-unwinding process, compared to just popping the stack and returning. Lua is a bytecode-interpreted language, and explicitly stores the data needed for that unwinding on its (virtual) stack. So it's a little bit slower than not doing protected calling, but honestly, if you are worried about micro-optimizations like that then you are using the wrong language.

like image 170
Sneftel Avatar answered Dec 12 '25 05:12

Sneftel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!