Does LuaJIT use a fixed memory address for locals or better to store repeated calculations on "self"?

I’m wondering what would be a better design for a calculation that has to happen every update. To store the result on self, or if it’s okay to create locals (maybe preferred if the number of locals in an update at any given time is limited, since the compiler could optimize to re-use the memory block for another local outside of the closure?) I’m trying not to create any performance drags in my codebase if possible since performance is already a concern. However, I also want to do some fun things which require lots of trig calculations.

The only way to know for sure is to measure it yourself, but I doubt it will make much difference unless you’re doing it several thousand times per frame.

And do you really need to do it every frame?

1 Like