Is there a performance benefit to setting functions within tables manually rather than using OOP?

Per https://create.roblox.com/docs/luau/metatables

“the code searches through the list for the index, finds nothing, and then checks if there’s a metatable attached to the table, returning nil if there isn’t one.”

Because of this, am I right in assuming that the first option in the example below is more performant than metatable because it avoids the nil index check?

local function Test()
	return true
end

local function CreateObject()
	local self = {}
	self.Test = Test
	return self
end

local Object = CreateObject()
print(Object.Test())

---

local OOP = {}
OOP.__index = OOP

function OOP:Test()
	return true
end

local function CreateObjectOOP()
	local self = {}
	setmetatable(self, OOP)
	return self
end

local ObjectOOP = CreateObjectOOP()
print(ObjectOOP:Test())
1 Like

A quick test supports my theory:

task.wait(5) -- Let server start up...
local Tick = tick() 
for i = 1,100000 do
	Object.Test()
end
print(tick() - Tick)

local Tick = tick() 
for i = 1,100000 do
	ObjectOOP:Test()
end
print(tick() - Tick)

14:14:49.054 0.0011115074157714844
14:14:49.056 0.0016574859619140625

OOP method took 1.49x longer.