Okay so my game utilizes a table with tons of keys that are tables with more keys. I was just wondering if there’s any sort of way I could somehow optimize the table. Here’s what the table is kinda like:
When you say optimize, do you mean performance? Or do you mean how the table is organized?
If you mean performance, you could try to eliminate the nested tables by doing somthing like:
local t = {
["key1/innerKey1"] = "value",
["key1/innerKey2"] = "value",
["key1/innerKey3"] = "value"
}
Where you just try to store everything in a single table.
But then, if you are trying to access values in an “indirect way”, you’d have to do additional work to generate the proper key.
Like:
-- For the sake of the example, assume that you don't know the values of string1 and string2.
local string1 = "key1"
local string2 = "innerKey3"
local key = string1.."/"..string2
print( t[key] )
So your CPU is now doing a different type of work to access the table values, by concatenating strings together. So this may or may not give you an overall performance gain, depending on how much time is spent concatenating strings, and the time that the Garbage Collector may spend cleaning up old string data.