Is it more expensive to send multiple arguments or a table with remotes?

Hello!

Basically the title. I’m looking for micro-optimizations for my script and was just wondering if it was less expensive to send a table containing multiple information, or if it would be more expensive to send the required arguments with a table or sending it as a tuple?

So basically, is

remoteEvent:FireServer(arg1, arg2, arg3, arg4)

more expensive than

remoteEvent:FireServer({arg1 = arg1Value; arg2 = arg2Value; arg3 = arg3Value; arg4 = arg4Value})

or is it roughly the same?

1 Like

For me, when more data is sent, more time will take the script to send data to a Remove Event/Function. In this case, the table send more information because is not just the data, it’s also the index of the data.

Aditional info

But take in mind…

When you send a table, only table data indexed by a number will be passed. For example:

Local script:

remoteEvent:FireServer({--[[This data is indexed by a number]][1] = "Hello"; --[[This data is indexed by a key]]Msg = "Hi"})

Script:

remoteEvent.OnServerEvent:Connect(function(...)
	local args = {...}
	print(args) --[[Will print "{[1] = "Hello"}"]]
end)

If you need more info, see: Bindable Events and Functions | Roblox Creator Documentation

1 Like

I am guessing the first line would be more optimized, kind of, because with the table, you are sending the table and then variables in it. I might be wrong

1 Like

Data should be sent regardless of its index. It’s only functions and metadata that don’t get passed iirc.
Edit: yeah, just checked the page you linked. What happens is with mixed-index tables. So,

local table = {[1] = '1'; ['string'] = 'str';} -- only [1] = '1' would be passed

whereas

local table = {['string1'] = 'str1'; ['str2'] = 'str2'}

would be passed as normal

@Interactivated Will keep that in mind, thanks!

I’ll probably wait a bit to get a few more answers.

1 Like

I believe both get serialized into roughly the same thing, the table one might be a few extra bytes but it shouldn’t matter.

Therefore the answer is both are equally expensive.

2 Likes

I did a little testing to see how much faster one is over the other, and the outcome of the results was that sending multiple arguments is pretty much the same as firing a remote with a table parameter.

image

I did find that multiple arguments were ever so slightly faster by an amount that would probably not be noticeable to the human eye, but in general, they can be used interchangeably.

One thing to note is that using several parameters might make your code readability much more difficult, and it is just best practice to use a set amount of parameters (I usually cap at 3), so if you feel like your functions need over like 6 parameters, you should consider just using tables

5 Likes

There isn’t a lot of difference. But yes, I’m right.
(Sending multiple arguments is faster than sending a table)