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?
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
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.
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.
Sending the number 1 as a string at 60 times a second.
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.
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.
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
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.
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ā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.