Can anyone list some techniques to save bandwidth with RemoteEvents/in general in a game? I want to try and optimize some of my netcode
I’ve heard of string.pack but how do you use it? It’s not documented anywhere on the dev hub
Can anyone list some techniques to save bandwidth with RemoteEvents/in general in a game? I want to try and optimize some of my netcode
I’ve heard of string.pack but how do you use it? It’s not documented anywhere on the dev hub
Disconnect unused OnServerEvent/OnClientEvent callbacks, delete RemoteEvent instances when no longer required etc.
This doesn’t do anything. There aren’t more requests being made because of the amount of callbacks.
This shouldn’t either, you should if you’re using temporary remote events for memory concerns, but it doesn’t make bandwidth better. (and actually it has to send a request to the client for that to be deleted, so…)
Exploiters can still trigger events which haven’t been correctly removed.
Use them as little as possible. In my opinion, you shouldn’t be firing an event faster than every tenth of a second, and you should not have more than two remotes that fire every tenth of a second. And try to send small amounts of data when firing them, so instead of a big table, send the key/index of the value and the new value of that in the remote.
Exploiters can send however many requests they want, that doesn’t matter.
They could use any remote Roblox has by default, or also just spam the server with requests.
If you’re worried about your listener in the server firing too much, set up delays.
If you have specifics, I know you mean general, but it’s always nice to know what exactly you’re doing with your requests and for what.
Firing remotes every Heartbeat or usually in a loop, it’s usually a sign that you could do something in a better way.
It would matter depending on the performance of the remote being fired (some are obviously going to be more performance intensive than others). It was a generic suggestion as I had little information to go off, ultimately you shouldn’t be too concerned about saving bandwidth use in-game.
You can find string.pack’s documentation on lua.org just use CTRL+F and type ‘string.pack’.
As for how to use it I don’t have a idea but hopefully you can figure it out.
It may help with saving bandwidth or it might not I’ve never used it.
As for general optimization its best to shorten things as much as possible.
Say player1 wants to buy the skill ‘Super Fire Beam’ instead of sending over the name of the skill they want to buy you could for example send over a ID associated with the skill so:
buyskillevent:FireServer('Super Fire Beam') -- Instead of this you can do:
buyskillevent:FireServer(44) -- 44 would be the ID for Super Fire Beam
While events that don’t get fired very often likely don’t need optimization it could be useful in some places.
As for tables and things like them you could do as Judgy_Oreo said and just sent the key and values or you could use HttpService’s JSONEncode and JSONDecode.
I’ve never actually ran into needing to optimize my netcode for bandwidth reasons but these are just the ideas I thought of on the spot I’m sure theres more ways.
Send as little data as possible and always try to send numbers over strings. Say you have an inventory system and Player1 gains an item with these values:
{ID = 7, Name = ‘Sandwich’}
Instead of sending this table you should send the ID only, then on the client use this ID to get the item information (presumably from a module in ReplicatedStorage). You should also only send changes in player data, if the player only gets one item do not send their entire inventory to the client, just send what they obtained. This is made significantly easier if you use a PlayerData module that handles these requests for you.
you could probably find more info on the dev forum
but from what I know its basically been deprecated and gives no documentation and I have barely any knowledge on its functions.
But what you could probably do is do serialization on the client instead of sending the entire info through remotes.
local remote = game.ReplicatedStorage.RemoteEvent
local default = {
HP = 100,
Speed = 30,
Attack = 20
}
local function Simplify(stats)
for i,v in pairs(stats) do
if default[i] == v then
stats[i] = nil
end
end
return stats
end
local stats = {
HP = 70,
Speed = 30,
Attack = 20
}
remote:FireServer(player, Simplify(stats)) -- sends {HP = 70} because thats the only differnce
Local Script
local remote = game.ReplicatedStorage.RemoteEvent
local default = {
HP = 100,
Speed = 30,
Attack = 20
}
local function FormStats(stats)
for i,v in pairs(default) do
if not stats[i] then
stats[i] = v
end
end
return stats
end
remote.OnServerEvent:Connect(function(stats) -- {HP = 70}
local stats = FormStats(stats) -- {HP = 70, Speed = 30, Attack = 20}
-- do something
end)