So I have noticed that some people may use the following code when sending data over to remote events:
event.OnServerEvent:Connect(function(player, ...)
local args = {...}
if args[1] == "Arm" then
if args[2] then
else
end
end
end)
And some people may use a table or a dictionary:
event.OnServerEvent:Connect(function(player, data)
if data.Status == "Arm" then
if data.Enabled then
--data.Enabled being a boolean and data.Status being a String
else
end
end
end)
I want to know if one is more effective than the other in terms of performance or are they the same?
In general, the performance difference is negligible. If you really need to find out, the best way would be to run benchmarks.
However, I assume Roblox serialises objects as strings before sending them. They would probably look something like this:
Dictionary: "{Status = 'Arm', Enabled = true}"
List / tuple: "{'Arm', true}"
Because lists don’t need to store the key, they can be stored with less bytes, which should improve network performance.
However, the best approach is to build code to be readable first, and optimise later if necessary.
Alright, thank you. I feel like using a dictionary is more organized and less confusing when reading your code, especially passing it through Remote Events
If we take code readability into stage, then passing a variadic parameter (... which also means having positional arguments) is very inferior to plainly passing a dictionary or tuple.