Which is more optimal? table[info1][item] = iteminfo1 OR table[item] = { alliteminfo }

I’m deciding on how to structure a database for an addon of mine that implements an inventory. For now, the (default) info about a type of item is structured somewhat like this:


Database[item ID] = {
	base = {
		maxstack = int,
		value = int,
		weight = int
	},
	info = {
		name = str,
		shortname = str,
		desc = str,
		shortdesc = str
	}
}

I realize that while this makes it easy for atleast me to read and edit item properties, it’s a very inefficient way to structure the database using multidimensional tables. To begin with, I’m going to use integers for table keys instead of strings, but I’m wondering how I should structure it otherwise.

Should I put all the info into a simple array (A), or should each type of item information have its own table, where the keys are item IDs and contain the value of this type of info for that item? (B)


A)
Database[itemID] = {
	maxstack (int),
	value (int),
	weight (int),
	name (str),
	shortname (str),
	desc (str),
	shortdesc (str)
}

B)
Database = {
	{	-- maxstack (int)
		itemID = int,
		...
	},
	{	-- value (int)
		itemID = int,
		...
	},
	{	-- weight (int)
		itemID = int,
		...
	},
	{	-- name (str)
		itemID = str,
		...
	},
	{	-- shortname (str)
		itemID = str,
		...
	},
	{	-- desc (str)
		itemID = str,
		...
	},
	{	-- shortdesc (str)
		itemID = str,
		...
	}
}

Also, I should mention that not all items will have all of the values. For example, some items may be equipped and consequently have additional variables; Some items are mere clutter items and can’t be interacted with in many other ways than that you can put them into your inventory.

Neither structure A nor B present any noticeable difference in how much easier and/or faster it would be for functions in the addon to retrieve the values, other than that they’re both faster and easier to retrieve than the current structure (although the current structure is easy to understand), and I haven’t been able to find any clear statement of whether one is faster or uses less memory than the other; Only that they’re both faster and use less memory than the current structure.

plz halp?

They each compile into exactly the same thing.

Just pick one of the other, Client wouldn’t notice anything on which is faster to retrieve data.

I’ve used both methods above for tables, personally I prefer your first one.

The first one will take up a few bytes less memory.

Thanks for your feedback! The first it is. Like Aide said, it’s much easier to read, too, and if it also uses less memory (although it is unnoticable) it’s obvious it should be used.