How to measure data size

How do I measure how much space a specific value in a datastore is taking up?

1 Like

i guess there is plugin for datastore not sure if that can help

1 Like

The question is how, if there is a plugin that does it I want to know how it works.

Create or get a module with the information and export it, DataStore Editor can do it for you.
Next, open the file settings and see how much it weighs:

Module: return 10
File: image

Here’s something bigger:

Module
return {
    "Sword",
    "Apple",
    "Cookie",
    "Taco"
}

File: image

That works, but I don’t want to have to download a .lua file everytime. Is there any easy way I can just make a function and insert a value and it will output the data size, potentially with HttpService?

With this function:

local Data = game:GetService("DataStoreService"):GetDataStore("Inventory")
local suc,dat = pcall(function()
    return Data:GetAsnyc("Sword")
end)
print(game:GetService("HttpService"):JSONEncode(dat):len())

Original post:

It does not give exact, but it works.

5 Likes

The above post gives some code that works but I will go into more detail here.

Datastores encode the what you put in into JSON. So, to get the size of a value in a datastore, just encode it into JSON using HttpService:JSONEncode then get the length of the string.

2 Likes

How accurate is that though? because in the post provided

not each character is exactly 1 byte

It is accurate as string.len returns the number of bytes, not the number of unicode characters. If you do string.len on a unicode character you will see it returns 2 or more.

1 Like

Can you provide an example of string.len returning a different number than the characters? Because for me it’s returning the same.

Try doing string.len on an emoji or some other unique character. I’m on mobile so I can’t test right now but something like this should work:

print(string.len("😔"))
1 Like

I see it returned 4, thank you for the help!

Also thank you @SOTR654 for the help!

Eh… You’re welcome! Happy to help xd
I still say that it is not exact because it is the size of the string, but not in bytes as it is saved by roblox

1 Like

Yeah I noticed a little discrepancy between the file, it should be fine though for what I am trying to do.