Which takes up more space to save?

Hey everyone! I am going to use DataStores to save strings but I was wondering about turning the string into numbers so that it’s more compact, and can save more. Creating UID is tedious for me and takes up a lot of time, I’d prefer to save by string. Here’s an example
‘Test Item’

I was wondering if this is more efficient than turning it into numbers, ie t = 1, e = 2, etc.

If I was to turn it into numbers, I’d need something to separate it with, so I know how to unscramble the code (i.e 1a2 = te)

I’m not an expert on saving by string size, so which would is better. Imagine each string is roughly 7-25 characters.

I’m wondering this because I feel as though numbers are less bytes than strings or someting, I have little to no knowledge in this field.

1 Like

Each digit in a number can have 10 values, 0123456789.
Each character in a string can have 256 possible values I think.

This means strings take up more space in datastores. You shouldn’t have any problem storing the raw values either way, as the roblox datastores are pretty large. What are these UID’s for?

2 Likes

could this be of use to you for turning strings into numbers?

https://developer.roblox.com/articles/Built-in-Functions-and-Variables/Lua#tonumber

I need to save the UIDs as its the name of the item. Is prefer not to just do 1,2,3 for every single item as when it’s another item its another ~5 seconds, which adds up for 2500 items. 2500*15 (roughly the average string length) * 1(however much space 1 string takes up, idk this) is a lot. especially if that multiplier is higher.

what letter should I use to separate each number?

I don’t think that’d work. I’d just make a custom function. I can do all this, just need to know if I should.

Why are you saving items? Is this part of an inventory system? Does every item need to be saved to a different key or could you put many items in one?

As you proposed it, this makes little sense. First, numerical values byte size is fixed, so you can’t encode a big string into a single number without overflowing. Secondly, as you said you need to separate the numbers by something which in your example is using a character already, how are you encoding that into a number?

Anyway your idea is valid but the way to approach it is using a sequence of integers and encoding the reduced alphabet in the 32 bit length Lua numbers. However you need bit wise operations to do so which Lua 5.1 doesn’t support natively.

Then again to save a table into a datastore you usually encode it to json which transforms all your data into a string, killing any benefit of your encoding, so you would need to save in sequential keys. Overall I wouldn’t recommend it.

Yes, you’ll save space, but unless you’re nearing the limit (260,000 characters), it would honestly just be better to store the data as-is.

2 Likes

I understand that it’ll still be a string, but my real question is: Do numbers take up less bytes than strings / give me more room in the DataStore limit

The answer was implicit in my response. Strings are not fixed size and every character takes 8 bits. Numbers are always 32 bit in Roblox. Hence a string with 3 characters (account for null terminator) already takes the same space as a number.

There’s also the fact that when using Unicode, each “character” can be up to 32 bits.

If you really want to save space on a large bit of text, consider a text compression/decompression library such as LZW.

Can’t vouch for this one, but the author is pretty well known.

1 Like