More efficient way to send remote event parameters?

Hello,

For a current project I’ve been working on I send a lot of remote event calls to the server. Some of these server calls send 5 separate parameters of data. I realize the more data you send the slower it reaches the server. Would it be more efficient to concatenate these parameters into one string in the form of “type|type|type|type”, and then send that and dissect it in the server? Any help or input would be great!

  • BigThunderBoy

You’re dealing with such a small difference in packet sizes.

Are you gonna be firing remotes so much that you need to optimize that much or do you just wanna know?

What’s the firing rate?

What type of data? Can it be expressed as numbers instead of strings? If so then that is going to be the best way.

For example, say I was sending effects to clients to be rendered there and I had three types of effects.
I could do something like:

effectEvent:FireAllClients("Explosion", position)
effectEvent:FireAllClients("Sparkle", position)
effectEvent:FireAllClients("Fire", position)

Or I could make a module with an index of effects to numbers and then only send a single number to denote the type of effect:

Module:
return {
  Explosion = 0,
  Sparkle = 1,
  Fire = 2,
}

Server: 
local EffectTypes = require(game.ReplicatedStorage.EffectTypesModule)
effectEvent:FireAllClients(EffectTypes.Explosion, position)

Client:
local EffectTypes = require(game.ReplicatedStorage.EffectTypesModule)
effectEvent.OnClientEvent:connect(function(effectType, position)
  if effectType == EffectTypes.Explosition then
     --- Explosion effect
  end
end)
4 Likes

So my game involves the player placing crops at a specified location and then the crops grow. These events fire rapidly. I handle the growth calculation for each player on the client and then send a remote event to replicate the growth stages on the server. I’m sending in a seedName type string, location string (“x:y”) , and stage of growth (int) in my most rapid remote event calls to handle growth. Sometimes there is a noticeable delay in replication. Should I create a local copy so the feedback is immediate or is there a better way to optimize this with the given parameters?

I think the first thing to think about is do you need to send remote events so rapidly? Cutting down on the number of events would be a much better approach than trying to make marginal gains by condensing the information. Additionally handling the growth calculation on the client seems like a bad practice because it could be exploited.

I would recommend just calculating the growth level on the client based on the time planted. A client could just be sent the plant type, location and time planted and display the correct growth stage. When the plant is harvested, the server can simply check does the time planted to make sure it is in the correct growth stage.

2 Likes

Thanks for the input! I definitely will try to figure out some way to cut down on my event calls. Big fan btw!

1 Like