Will replacing string keys with an index help with memory if I'm already using JSON?

Lets say I have a data table

{ superlongstringname = 1, superlongstringname2 = 2, superlongstringname3 = 3 }

And I am storing multiple clones of that table, but with different values
{ { superlongstringname = 3, superlongstringname2 = 1, superlongstringname3 = 5, }, { superlongstringname = 1, superlongstringname2 = 2, superlongstringname3 = 3, } }

And I JSONEncode said string -

Does JSON encoding handle compression of the string keys, or would I get a large benefit from converting the string keys into a numbered index?

This is asking for the potential case of thousands of these tables being created

1 Like

JSON encoding does not perform any compression. It simply changes the format of the data. I recommend compressing the JSON in its entirety as opposed to using less expensive keys, but the latter will still yield a lower memory footprint

1 Like

If possible, use buffers instead: https://create.roblox.com/docs/reference/engine/libraries/buffer
The only case where you TECHNICALLY can’t use buffers is Roblox plugins or HTTP requests.
For buffers, your algorithm has to know the template to deserialize.
Etc know where is what datatype
Otherwise, string terminators may also work for dynamic ones.

2 Likes