Is it a bad idea to use module scripts on the server to store and manage frequently accessed and updated data, such as a table of structures in a game? I initially thought this approach was good for organization across scripts, but I’m concerned about potential performance issues with frequent reads and writes. Are there better alternatives, or ways to optimize this setup while maintaining modularity?
Kinda at a crossroads in my game development so want to make sure I am pursuing the right approach! Thanks in advance
modules just return the same table for every script that requires it, once you have the table theres no performance overhead and you can do whatever you want with it
Isn’t that not entirely the case though? If one script updates a value inside a module script, other scripts dealing with that value will be affected by the change.
that has no performance overhead. tables are a dynamic type, any variable that holds a reference to the same table, even across scripts, affects all the others. this is a behaviour built into the engine and itd probably be less performant if they somehow made it so it didnt. the same table is the same table, doesnt matter what script your getting or setting values from
This is the way. But seriously, ModuleScripts are the solution for frequently accessed data and improving your workflow. One thing I think is important to note, is that any change to a Module from the server will not inherently replicate to the client.
They are effected yes. But they are only effected in the sense that reading the data it will be different. It’s not like an event that updates something in every script. It’s more like tying specific memory regions together so more than one script can access it. So if one changes it the other can see it when it tries to instead of needing to react. So there isn’t a ton of performance overhead.