Am I even doing OOP right?

Alright so it is faster localizing the functions, so should I do it?

I know its such a small amount

Asked 5 years, 3 months ago

Also the question is about Lua, Roblox Lua and normal Lua are very different, and Lua 5 years ago vs now is very different as well.

Roblox Lua has same functions but are actively modified, maintained and optimized, and with the introduction of Luau, it is safe to say Roblox no longer even uses Lua anymore, it uses a heavily modified version “Luau”.

1 Like

Mate, the difference between those times is literally just 2 milliseconds which doesn’t even span to 2 frames in 60hz and so the optimization is so slim that it’s not faster at all times. In order to have a noticeable difference you would need to do that iteration 1 billion times which is ridiculous and you rarely need to do 1 billion iterations normally.

It is slower, read the post again and the order of the output and the print statements.

1 Like

Lol the “faster method” is actually 0.002 seconds slower

What do you mean you literally said the one that localizes math.sine is faster

local tt = os.clock()
-- Faster
local sin = math.sin
for i = 1, 1000000 do
	local x = sin(i)
end
print(os.clock()-tt)

Oops, forgot to remove that comment. I copied directly from your code, look at the output results, not the comments.

Any time you “save” (negligible) by localizing you will lose by doing object oriented design 10 times over. OOP is not a fast paradigm in languages like Lua and while it’s not noticeable it probably wastes orders of magnitude more time in calling methods than you will get back from localizing every single operation in a script.

Just stick to normal, readable code. If you want to optimize, look into algorithms and their time/space complexity when you write them.

2 Likes

Screenshot_9

I think _ENV is something in lua 5.2 and they removed setfenv.

Luau (or roblox lua) uses a modified version of lua 5.1, which doesn’t have the _ENV table.