What exactly is the memory cost of a single ModuleScript object? How performant is Luau with reading large tables frequently?

tl;dr Need to know:

  1. How bad would it be for the game environment to have a large number of ModuleScripts for a single system, all of which return data to describe a sound?
  2. How performant is Luau at frequently reading large tables?

In both cases they need to be able to scale. I have around 500 sounds to serialise at the current stage of my project, so this can be worth 500 ModuleScripts or 500 entries in a table total when flattened down to one dimension. At late stages, these numbers can surpass several (ten) thousand.


I’m currently getting ready to serialise an entire hierarchy worth of sound objects to design for memory efficiency in my project. I’ve run into a few troubles while getting the serialiser implementation ready but I’ve finally got one that I’m proud of, with concerns.

One problem I’ve encountered is nested contents. Currently my serialiser is unable to read beyond a single layer so any nested folders are just transformed into dictionary entries. It’s not bad per se but I don’t know how performant Luau is with reading large tables and it might be an utter pain to serialise again when a change is made that needs to be written in (I have a plugin that non-programmers on my team can use to modify data for the game - sound support is my current focus).

My next thought was just to serialise every single Sound object into its own ModuleScript to make it easier to modify and manage in all respects. This could, however, lead up to this single system bloating my game environment up about +500 ModuleScripts now. While this doesn’t sound particularly swell, they’re still all getting collected into a larger table in the end. The memory use of the main collection table would be the same anyhow regardless of how I choose to break this up.

Need an opinion - is there a better circumstance here? Should I [1] create one monolithic sound data module, [2] many big sound data modules or [3] break them up individually? This is all pure data so the only difference is how many ModuleScript instances exist in the DataModel at one time and how painful it might be for me to maintain or set up a plugin to automate edits.


NO, leaving my Sounds as instances in the DataModel is not an option. Sound instances need to have their sound data downloaded and this can cause the client to consume a lot of memory to host them. Pure data does not have this same restriction and I can load them in/out whenever I want, thus the client only spends memory for sounds that are being actively used.

3 Likes

Realise how silly this question is. Not really any different than having the exact same count of Sound instances hanging around in the DataModel. Really then it just comes down to an issue of how performant Luau is at reading large tables. Marking this for now, won’t bother to delete - I have a feeling someone may have that same kind of “oh no, what shall I do” moment as I did today. It’s 2 AM.

Will update response if I end up resolving the read time myself too.

2 Likes

Read times should be exactly the same for arrays and should be almost the same for hashmaps.
As long as you don’t iterate through the entire table the length shouldnt really matter all that much.

3 Likes