Does making variable for function method optimize the code?

I’m currently working on my own game, and I’m making progress on optimizing my game. I want to know if this affects too.

Example :

--//Abbreviated Variables\\--
local VECT3NEW = Vector3.new
local rad = math.rad
local clamp = math.clamp
local abs = math.abs
local pi = math.pi

local ModuleOne = require(script.ModuleOne)
local Banana = ModuleOne.printBanana

--//Some random code\\--

print(VECT3NEW(1,1,1))
print(rad(5))
print(clamp(-5,1,10))
print(pi)
print(abs(-1000))
Banana("some argument",1,6,2,nil)

Not really, your using more lines of code rather than adding 2 words in one line. I don’t recommend it.

1 Like

This is slower rather than just calling the method directly, Luau does some under the hood optimisations that makes these basically free. Storing it into a variable means it loses these fastcalls (since values are never constant)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.