Dictionaries and Optimization

Hello DevForum users!

I just realized, dictionaries consume kind of a lot of memory or at least i think if you have a lot of information, and, i was wondering, is there a way to optimize them?, i use them to list every item of my game, but, recently i saw that they consume kind of a lot, and i need a way to easily optimize them.

I tried using items with attirbutes but it simply is just so hard and time consuming to adapt all my code.

Dictionaries are much more memory efficient compared to Instances or attributes so they should be a lot better. You are likely just implementing them incorrectly/inefficiently if they are consuming more than attributes. If you could show examples of your code that would help.

Of course!
This is for example one of the items, i have a total of 1116 lines of code of just dictionary stuff.

["Whearon Sickle Head"] = {
   	["Name"] = "Whearon Sickle Head",
   	["ItemsRequired"] = {
   		["Whearon"] = {
   			["Name"] = "Whearon",
   			["Quantity"] = 25,
   		},
   		["Stone"] = {
   			["Name"] = "Stone",
   			["Quantity"] = 5,
   		},
   		["Rope"] = {
   			["Name"] = "Rope",
   			["Quantity"] = 4,
   		}
   	},
   	["StatsRequired"] = {
   		["Intelligence"] = {
   			["Name"] = "Intelligence",
   			["Value"] = 18
   		},
   	},
   	["RequiredIntelligence"] = 20,
   	["Station"] = {"Blacksmith"},
   	["Drop"] = "Whearon Sickle Head",
   	["Type"] = "Material",
   	["Image"] = "rbxassetid://132548291556143",
   	["Description"] = "The upper part of a whearon sickle.",
   	["Quantity"] = 1,
   	["Price"] = 0,
   	["CanDrop"] = false,
   	["CanBeSelled"] = false,
   },

It might be possible that some things i can do is, just delete the stuff that is not ussed, and adapt a little bit of code to just verify if it haves that value in the item.

Is this retrieved from a ModuleScript in ReplicatedStorage or is it just sent to the client via RemoteEvent?

Its a Replicated Module, so i can access to it in both sides, i use verifications so if client modifies it it dosent affect anything.

There’s a few things you can optimize, like how instead of adding a Name = ... parameter, you can use the index name instead.

Also how have you been checking the memory usage to ensure that it is infact high and that this optimization is worth it in the first place?

1.-I use the Name param because of having like names in the items i can change without changing any data.
2.-I used the LuauHeap feature in the console, took some snapshots and thats it, seems like arrays is getting a lot of memory, i think.

Sorry low quality (I dont really spell that good)

1 Like

Is there a way for you to make a system that only loads parts of the dictionary when you need it?

Such as only loading weapons when you go into a weapon store.

I firstly need to know how to do that hahaha.

Like seperating your main module script into multiple module scripts you could load individually when needed.

So you mean separating each item into his own info?

If thats the case, how i would prevent them from loading in first place?

These verifications wouldn’t be needed, as if the client modifies it, the server and other clients wouldn’t even see the changes made, only the client who modifies it. And then you shouldn’t be validating the data from the client either, maybe these verifications you’re running are using memory as well :man_shrugging:

And like @Katrist said the Name = … parameter is not needed as the index name is the same.

Not to mention for the ItemsRequired parameter you could just do…

["Whearon"] = 25

Implying the quantity is the number and the name is the index

["Image"] = "rbxassetid://132548291556143",

instead of adding rbxassetid:// to each image you could just add the ID, and in the script concatenate this.

ALSO not to mention that these “optimizations” you’re trying to make are very minimal and most low end devices will be able to handle things like this. Unless you or your players are experiencing lag or heavy memory usage, why bother going through the trouble of optimizing?


And if it’s being slow, causing lag, or wtv

Worry about making your game fun and getting it out there

If you’re interested in learning more about programming myths that waste your time, you can watch this amazing video released by Fireship

1 Like

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