How to pass less data to remotes?

Is there a good way to pass data that consumes less memory for remote events/ bindable events?
For example, now that roblox introduced bit support, what if we wanted to only pass in a single bit like this: 0x00000001? Roblox only has a single number datatype so the size this would still be the same as passing in the integer 2.

I realized that bit masking could be useful too, but that takes a little bit of work to organize and parse everything. Does anyone have any tricks they use?

Thanks

This is a pretty vague topic. There are several questions I have that are left unanswered through a read of this post.

  • What are you sending that youā€™re trying to lower?
  • Why are you trying to do this?
  • How often are you sending? Whatā€™s your implementation?
  • What do you think youā€™ll gain from achieving this?
1 Like

Well the post is supposed to be vauge because I am asking this in the most general sense. I would like to find any solution that could lower memory usage. I pass literally every single datatype you can thing of for my remotes: userdata (tables,real objects, etc.), integers, booleans, strings.

So if for any of those types thereā€™s a little shortcut I could use, I would greatly appreciate it if someone could share their methods.

For my case passing in less data is needed because I fire remotes at least twenty times a second, each time the remotes contain many bytes of data due to the number of parameters Iā€™m passing. Imagine passing a table of like ten values each fire event, 25-30 times a second, multiplied by 5 or 10 players. The reason I need to use less memory is because my gameā€™s responsiveness is dependent on it. The less lag, faster data processing, the better

1 Like

What are you trying to achieve? You are probably doing it inefficiently.

Other than reworking your structure or making everything very bare bones (for example, instead of booleans, 0 and 1), there is no shortcut. A vague post doesnā€™t help, because this is a very specific case.

As for firing remotes 20 times a second, you should have no need to do that at all. Whoā€™s firing and why? Code structures should not have reason to fire this often.

1 Like

Unfortunately I need this many events fired per second. These remotes are not even being fired at a constant rate, but rather when a player state is changed, e.g. walking, running, jumping, climbing, etc. The game is designed to be very dynamic as a lot of things change and must be replicated. In fact, Iā€™m using a custom CFrame animation system similar to Phantom Forces. They too need to fire remotes many times a second to replicate everything. Of course, my animation system is optimized so I donā€™t necessarily send over every frame to play, but I still have to send a lot of information.

My game usually receives over 3000 requests a second on a full server. Iā€™ve been able to reduce receive rate from 90 KB/s to 40 KB/s by converting all the data into a single string.

Send the number 1 at 60 times a second.
image
Sending the number 1 as a string at 60 times a second.
image

2 Likes

This is an interesting solution. In the case of userdata, like in-game-objects, how did you encode/decode your references to these objects?

What Phantom Forces does, and any other game with a proper network model, is it tells a client ā€œRun this animationā€ and the client does that. There is no need to send the exact position of each component in a model at 30 FPS just for the sake of animation. Do the same for bullets - draw a bullet with x velocity and in y direction, and let the client figure out where to animate it towards. Donā€™t send the new position of the bullet each time. Let the client manage their own visuals.

2 Likes

Iā€™ve never had to send in-game objects over remotes so Iā€™ve never attempted to optimize my remotes in that way.

I guess you could just send the objects path using :GetFullName() so you can send the object over as a string and have the client/server grab the object using that.

image
image

Yeah thatā€™s exactly what I do. I have a specific string to pass for each animation I want to play, not a cframe or position datatype every frame lol. I did mention this already, but thanks

Yeah I was thinking of that too. I guess I would need some preprocessing to parse the strings, and also check if the objects still exist. Thanks for this string idea lol. Did you happen to encode your stuff to JSON or did you use a custom encoder

I just send concatenated strings separated by a ā€œ;ā€.

By converting everything into a single string, even if it is more efficient somehow, does use the same amount of memory. true/false as a 1 or 0 in a string still takes up eight bits. (Iā€™m assuming based on context and not my crappy memory that bools take up more bits than they should in Lua)

Now, rather than making the string ā€˜rawā€™, you could sort of compress it. For example, if you sent an ā€˜aā€™ in the string, it would mean several booleans instead of just one. But this would require a lot more processing power than I recommend, especially at 3,000 per second. If youā€™ve already done this, and it works, good on you. But I donā€™t personally believe that Lua is the language to be making such costly compromises merely to avoid decent programming practices.

2 Likes

Yeah I can see that too. I remember someone posted the memory usage for all the datatypes and booleans for some dumb reason still used an amble amount of space. Unless roblox can introduce a new datatype that will be specifically catered for passing in small bits of information to conserve space, there seems to be no clear-cut solution. Games heavily reliant on remote replication could benefit from this, but thereā€™s no strong demand for it I guess.

I think Iā€™ll mark this thread as solved though

Iā€™m guessing roblox does something else behinds the scenes when sending data over remotes. From my experience, converting numbers to strings has always reduced the send and receives rates over the network.

1 Like

Iā€™ll try this one out though. Thanks!