Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[dt][1] = {} or table.insert(dt, 1, {}) or rawset(dt, 1, {}). What is the best to use?

Hi guys. Today I want to update my database. I dont know if I want use metatable so I want optimized my script

My first question is, can i use rawset everytime or just in a precis circonstance?

My second is what's the difference on table.insert/rawset/t[i] = v.

Like what's the difference on pairs, ipairs and next in the new luau. Articles here

1 answer

basically the best to use is the Table[index] = value( [dt][1] = {} ) and i think you can use the rawset every time, but is more used on metatables.

For the question 2:

--[[
 table.insert -> can just add elements by a number in index.
 rawset -> same of `Table[index] = value` but can bypass the metamethods
 `Table[index] = value` -> can do all, and is the most faster way
--]]

so basically table.insert and rawset is more slow, then use the Table[index] = value which is more faster

Edit: Roblox Lua VM Updated, then all methods will be good to use, you can use whichever you prefer, but its recommended to just use rawset in metatables.

Hope it helped! :D

This discussion is preserved as it was. New answers, comments, and votes are closed.