Is it faster to use rawequal, rawset, rawget

Is it better to use these functions instead of using t[1] = 2
If so how much does it save?

The purpose of these functions is in no way of performance. It’s solely to set, get, and check the equality of a table without invoking the corresponding metamethods. For example, using rawget will successfully get a certain element from a table without the __index metamethod firing. This can avoid stack overflows where the method firings within itself, sort of like a loop.

Check out the DevHub for more info.

1 Like

I think you don’t understand too much, rawset() will not fire __newindex because doing
t[1] = 2 in __newindex will cause stack overflow
example;

local t = setmetatable({},{
  __index = function(no)
end
__newindex = function(self,i,v)
          self[i] = v -- stack overflow
         rawset(self,i,v) -- no stack overflow
   end
})
t.hi = true

So its only purpose is for metatables ?

1 Like

It’s main purpose is for exploiters to change variables locked by constant declares

Yes, it’s only purpose it’s for metatables…

Thats not its main purpose, but metatables were never meant to add ‘security’ to your code from other people modifying it

2 Likes