That’s fair enough. That’s a respectable amount of research you’ve done on it.
Here are some numbers if you’re still curious.
Vector3s use 4-byte floats to represent the numbers for the sake of space. Luau uses 8-byte floats. If you try to handle the axes of a Vector3 manually, they become 8 bytes. In other words, if you care about space, the first of these is better.
-- only sends 12 bytes, plus 1 or 2 more bytes to specify that this is a Vector3.
remote_event:FireServer(some_vector3)
---
local x, y, z = some_vector3.X, some_vector3.Y, some_vector3.Z
-- sends 24 bytes.
remote_event:FireServer(x, y, z)
If you do want to store something using strings, base-64
is the equivalent of 0.75 bytes per letter. string.pack
essentially uses base-256
and stores a full byte per letter. Given the options, string.pack
is both faster and more space efficient. In addition, string.pack
is capable of converting 8-byte floats into 4-byte floats for the sake of space, same as how Vector3s are stored. The caveat in our scenario here is that a 4-byte-per-axis Vector3, which takes up 12 bytes total, would take up the same 12 bytes with string.pack
.
That’s one of the main purposes of string.pack
though: fitting x
bytes of data into a string that takes up the same x
bytes of space for compatibility with systems that use strings.
As far as shortening stuff and shaving off decimals, it’s really not worth it. You have a couple of options, and none of them are good. The first thought is that you could just chop off the decimals. Mathematically, this would still be an 8-byte float. You could do it as a string, and store it as "4.56"
, but that alone takes up 4 bytes for no extra gain. It’s one byte per letter, but you’re only storing 0-9 and a decimal, essentially base-10
—the worst of all possible cases.
"4.56"
could theoretically be stored in a smaller amount of space if you convert it to a custom base-256
system, but you’d run into a few snags. You could overcome them with some understanding of float systems or what-have-you, but ultimately it would bring us back to performing processing in Luau, which is overhead you probably don’t want.
In summary, this is a great concept to think of and learn about, but existing systems are designed to handle this as efficiently as possible. Except in the case of long-term storage of massive quantities of data, it’s best to let the CPU’s natural affinity for floats and Roblox’s decade-and-a-half of network experience do the work for you.