In terms of performance, is it better to send a table with data or tuple arguments over RemoteEvent?

Hello,

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?

2 Likes

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.

2 Likes

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

1 Like

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.

1 Like