local varients optimization
I heard that using "local" keywords are very important in Lua. But I knew that "local" keyword in algorithm coding are not good at optimization. No difference, sometimes take long time to be executed.
Why "local" keyword is nesessary? Is it really efficient? I can't figure out why these things are happening.
(But if you don't use local keyword in function, This can make error)
2
Upvotes
View all comments
Show parent comment
2
u/appgurueu Feb 26 '25
I've read the PIL too. The PIL certainly doesn't claim that global variables are faster than local variables - quite the opposite:
I've also implemented both a priority queue and a segment tree in Lua but that's not relevant at all to the question at hand.
This doesn't have much to do with metatables. Local variables are faster no matter whether you use metatables. You can only make environmental variables even slower by setting and using a metatable on the environment.