I am trying to find a neat way to reference my modules. I am currently considering this method:
local tree = {
server_modules = run_service:IsServer() and {
},
shared_modules = {
classes = {
remote_connection = require(replicated_storage.framework_shared.classes.entity.remote_connection)
}
},
client_modules = run_service:IsClient() and {
},
self_modules = {}
}
This feels like a comfortable way of referencing for me, but there are some problems.
Generating a table; tables could be expensive, especially if they are being used in every modulescript.
Performance could lower due to higher memory consumption.
I am aware of not needing to reference unnecessary modules, and the reason why server_modules and client_modules exist together with a logic gate is because this is in a shared service.
Sorry if I sound a tad bit impatient, there are just some responses I kind of expect.
I know that tables could come at some costs, but I don’t know how extreme they would be in this scenario. If anyone could offer some advice, please do.
I am not the most knowledgeable on optimization in data structures on Roblox, but I believe you shouldn’t worry too much about the difference in optimization in terms of modules. The number one key that I learned in Roblox Studio is to embrace your style in coding and scripting. Optimization is a process and generally the only cases where you need to worry is your main game code. For example don’t define loose variables or if you have a large algorithm, these types of optimizations are significant. Otherwise, I see nothing wrong with your methods, as long as you feel comfortable with them. Be open to learn new methods, implement them and keep testing.
TLDR: your fine, don’t worry too much about the memory consumption, if I recall correctly it is negligible. If you really find this bothersome, run some tests by playing your game and checking the stats (although this is pretty stochastic, I wouldn’t dread too much about the results unless it is consistent).