How do I get the size in Kilobytes from data? (tables, strings, etc)

I wanna know how I can get the size in KB’s about how big is the data I’m testing. I don’t know how to do it, and I don’t know the math.

I would also like to know additionally if there’s any resources around to compress tables / strings. Mostly tables.

1 Like

Use string.length or put # infront of the variable.

If you wanna measure a table:

json encode it and then put # infront of it or again string.length.

local TableVar = {"Item1", "Item2"},
local HTTPService = game:GetService("HttpService")

local TableInJson = HTTPService:JSONEncode(TableVar)
print(#TableInJson)


Keep in mind however, the data is in bytes, to get it in kilobytes, divide by 1024!

Yes there are ways to compress tables, again by putting the table into its JSON format and then using a LZW compression system. (same applies to normal text)

4 Likes

I’m confused, isn’t it multiply by 1024? Aren’t bytes smaller than kilobytes?

1 Like

1024 bytes are 1 kilobytes. So if bytes if 100 then bytes/1024 = 0.09765625 kilobytes.

2 Likes
local B_Upgrades = {
	{1,2,3,4},
}

print(HttpService:JSONEncode(#B_Upgrades))
wait(3)
local B_Upgrades = {
	{1,2,30943856094850698409586},
	{},
	{5}
}

print(HttpService:JSONEncode(#B_Upgrades))
--[[
 18:06:43.351  1  -  Client - Sample:15
 18:06:46.363  3  -  Client - Sample:24
]]

I dont get it, JSONEncode seems to be getting the number of values/indexes stored in the table. Not how big the entire table is in bytes.

Is there any other method?

You’re supposed to do #HttpService:JSONEncode(B_Upgrades) instead.

1 Like

how does this work when the value in a table is an Instance? I’m sending a table containing many instances to the client, and trying to measure the table size using JSONEncode is inaccurate because the instances are changed to null in the process, while remotes successfully transfer them.

We would have to assume roblox is sending the instances as unique identifiers (4 or 8 bytes) instead of as a string. Remotes are also likely sending numbers as floats (4 bytes) instead of a string. Strings are usually much more data to send, they will be one byte per character and another 1 or 4 bytes to store the end of the string.

If you are trying to reduce your game’s data throughput it’s best to reduce remote calls first then reduce strings inside those remote calls.

seems like it looks something like this:

I’m gonna have a table on the server that’s storing a TON of data, depending on what kind of game is using that table. In a building game, for example, data about potentially thousands of parts could be stored and so if the table gets too long, I won’t be able to send all of that data to the clients in one remote call. I’m trying to figure out at what points I would be splitting the table into multiple remote calls, that’s why I need the table length in bytes.

It might look something like that, but that post is trying to get the memory address. Since the RAM in your computer isn’t the same as the Server’s RAM this address can be very different and they will need to send a unique ID both the clients and server can agree on; it may be only visible to Roblox developers


Depends on what your server-side data is, Roblox sends thousands of part updates to clients every second! Try leveraging roblox systems before using scripts in such cases. Roblox can handle updating physics much better than Lua ever could. Adding and Removing parts should be handled by Roblox, if you need to keep track of parts server-side then keep that tracking only in your server-side script.