Actually its 30% faster when you localize the global function
That âsqueezed out performanceâ is very small, if any. There is no reason to do it.
Like I just said when your hands are tied and you need the extra performance, this can help
Even if your hands arent tied its good practice
It only wastes your time and distracts you from optimizing the actual logic.
It doesnt waste anytime, and also you usually do this when your going to use those global functions in actual game logic
If anything it saves time and boosts performance
Non-local: 0.719 (158%)
Localized: 0.453 (100%)
no lol no way itâs gonna be fast like that, it doesnât make sense;
Considering the âperformance gainâ it gives, it is definitely a waste of time. If you are at the point that you need this micro-optimizations, revise your code logic. I used to do this a while ago, only to realize my actual code logic was inefficient, I spent an hour optimizing the various globals I was using.
It does make sense you should educate yourself on how lookup tables work
Itâs not a table, itâs a luau function;
In the long run, does it really matter if you optimize a little math.sin
or the stuff that actually needs to be optimized.
lol I was about to say that
But those lua functions are stored in hashtables and retrieved when you use them
Basically they are stored in the environment
_ENV["math"]["min"]
Why would you even do that? wth? Itâs not that big of performance impact dude. Code isnât that slow.
Optimize your functions, use modules,disconnect RBXScriptSignals and you should be fine;
It just makes it more painful
Yes doing all those things is great, but localizing global functions is always a good option
I literally never heard anyone say thatâs good to do, youâre essentially just shorting theyâre name. From what I know the only thing bad about globals is being localized, later itâs fast and ok.
Donât you think Roblox would optimize Luau to do something like that already? And they did!
What you are doing is basically creating another variable which would use more memory;
And if you declare a variable, the parser has to manually go back to the point where the variable is declared, retrieve itâs value from the main table anyway, and then push it towards where the variable was called.
Alright so I get it now, but I wasnt totally wrong; doing this before the roblox Luau optimizations helped but now it has little to no impact
Thanks for clearing it up
Never has, never will be. Letâs break it down step-by-step:
In the memory, there is already a slot for print
that has the value to call the print
action.
When you do local print = print
, you are just creating yet another memory slot for the print
action. This wastes memory.
Was bored so I tested your benchmark code in Roblox Studio. Here are the results:
0.033565000165254
0.035869099898264
Code:
wait(10)
local t = os.clock()
-- Faster
for i = 1, 1000000 do
local x = math.sin(i)
end
print(os.clock()-t)
local tt = os.clock()
-- Slower
local sin = math.sin
for i = 1, 1000000 do
local x = sin(i)
end
print(os.clock()-tt)