Search code examples
performancereflectionlua

What are the performance implications of using Lua's `debug.getlocal` function?


What are the performance implications of Lua's debug.getlocal function for the standard Lua reference implementation? I know that reflection tends to have a certain amount of overhead, depending on the programming language and its implementation, but haven't been able to find any information on what it might be.

I'd also be interested in its impact in other implementations, such as LuaJIT.


Solution

  • It's going to be difficult to answer this question, because you don't specify what you want to compare it with. If the alternative is not to make the call, then sure, making the call will be slower; on the other hand, if you're writing a debugger and need to get information about local variable in some function, I don't think there is any other way to get it, so would the performance of the call be a concern in that context?

    If you have other options of getting the same information, then, as others suggested, you may want to have a test that mimics your case to see which of the options performs better. It may be useful to review answers in this SE question though.