Would Changing a Dictionary to a Array increase Performance?

So right now i Store my Data like this:

{Position : Vector3, Velocity : Vector3, LifeTime : number} --Standard Dictionary

Then i have a Table where i store like thousand of these Dictionaries.
I am wondering if changing it to

{Vector3, Vector3, number} --Indexes are only numbers

where the indexes are only full numbers would actually make it better for performance?
If not then if that will atleast help with memory? And is it even worth making the code a little bit less readable?
Or maybe i should go with something crazier like this:

{Vector3, Vector3, number, Vector3, Vector3, number,} --No table nesting, there are 2 objects in this example.
1 Like

Removing the indices will save space when saving the data if that’s what you’re asking, yes.

When the table is JSON encoded (this happens when you actually save the data on the backend), assuming you’re serializing your Vector3s as {x,y,z}, a table with numerical indices will look like this: [[1,2,3],[1,2,3],1] (19 characters) whereas a table with string indices will look like this: {"Position":[1,2,3],"Velocity":[1,2,3],"LifeTime":1} (52 characters).

These string indices do take up a considerable amount of space and will make your data storage less efficient and will allow you to store less data. This difference will become even more apparent when you’re scaling up to thousands of these tables as you mentioned you’re doing.

In my opinion, as long as you have a standard format/layout that you are following for your data, the reduced readability is a fair tradeoff for making your data storage compact/efficient.

3 Likes

it should run at the same speed but you use more memory

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.