Am I even doing OOP right?

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.

1 Like

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.

1 Like

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.

1 Like

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;

2 Likes
4 Likes

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)
2 Likes