RepCompressor - Compress Vector3s and CFrames

Hello Developers! Are we still sending CFrames or float points across the client-server boundary in the year of our lord 2024?

This is what you’re actually sending with a CFrame value:


Who knew that something seemingly simple like a position and a rotation would be 12 values of mostly useless numbers? Now what if we put it through the module?

Yup, you can get rid of half the values and the float points, which is like getting rid of a bit more than half of the data you’re sending across the client-server boundary.

Module is here:
RepCompressor.rbxm (1.0 KB)

Documentation:

--Converting a CFrame to 2 Vector3s
local pos,rot = module:toVector(script.Parent.CFrame*CFrame.Angles(0,math.rad(45),0))
--Converting the 2 Vector3s back into a CFrame
local cf = module:toCFrame(pos,rot)

print("Position: ",pos," | Rotation: ",rot)
script.Parent.CFrame = cf
print("Finished")

--Compressing a Vector3 (useful for getting rid of float points from something like mouse pos or vel)
local newVec = module:compactVector(script.Parent.Position,3)
--Making it usable again
local newerVec = module:expandVector(newVec,3)

Let me know any bugs or problems you have in the replies. Also feel free to credit me, or don’t. I don’t really care. Bye bye!

7 Likes

I am pretty sure lua uses doubles for numbers internally, not integers. Hence, there would be no benefit in converting doubles to integers before sending them over the network.

(source)
https://www.lua.org/pil/2.3.html

I’ll look into this once I get back from school. Either way it’d still be better to convert a CFrame into 2 Vector3s when you need to send it across the server.

No it wouldn’t. Instead of sending one value you’re now sending two. This doesn’t necessarily “double” the data but it doesn’t significantly compensate for what you previously had.

Lua runs on C++, so it makes sense to see how other C++ libraries do it, like this one.

1 Like

To truly test its effectiveness, use the network byte counter plugin.

Alright, so I did some testing and found that Roblox optimizes sending the basic types very well despite seemingly sending much more numbers with large float points. Through a bit of brute force testing, on average sending data across the client-server boundary after passing it through RepCompressor is on average 1.26x less efficient. HOWEVER, I’m going to keep this module up although rebrand it for the purpose of saving data more efficiently, where getting rid of unnecessary characters when saving things like position values is ideal.

Do you have a link to this? I can’t find the plugin.