Why do some people localize globals?

I sometimes see people localizing globals, however I do not understand why they do this.

Example:

local setmetatable = setmetatable
local table = table

Why do people do this? I’ve searched around, however I am unable to find anything.

You can for example override the global function print.

local old_print = print
print = function(...)
    old_print("message: ", ...)
end

print("test") --> message: 	test

I’m not sure about this but from what i know is for the same reason they localise CFrame.new or math.min to optimize their games. Theres propably another reason but thats what i believe

image

Reference

  1. Variables
  2. Local variables in a global scope
1 Like

Some globals are imported which makes that process unnecessary (really wish boblox wasn’t vauge about it tho)
image
Edit: sauce Performance - Luau

1 Like

As far as I know, Roblox has made it unnecessary to localize built-in globals by performing the optimization for you under-the-hood.

1 Like