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.
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?
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.
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.
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.