What's better for performance? 1 script requiring modulescripts for executing tasks vs creating a script for a new task

This is something I’m very curious about, as I’m trying to create an extensible backend and I want to know which one would have less activity and thus, less impact on performance.

3 Likes

Could you clarify what you mean by “a new task”? Are you cloning a modulescript/script whenever you want something to happen? You need to be more specific.

1 Like

U can make more module scripts to put ur systems in there cause they are better if ur code is like complicated

2 Likes

i believe performance is dependent on how you write your script as in how you manage loops, events etc… but using module scripts or using multiple script instances is all about organization and doesn’t have to do with performance

2 Likes

module script is better in my opinion
because script needs to be deleted by debris service if it is used for minor problems

3 Likes

image
Hope the image helps with the “1 serverscript with modulescripts” part.

2 Likes

AFAIK there’s no actual reason to build your modules like this as a bunch of separate functions other than hot-swapping modules with other ones (which I don’t think is good practice anyways).
Instead of returning a function, you can return a table of function. Way less to keep track of, way less modules to require.

EDIT: As for performance, you’re requiring less modulescripts. So that’s less function calls for require(). But requiring modules would mostly have a negligible impact on performance unless done excessively.

2 Likes

If you’re curious you can open the MicroProfiler and check in what order they’re ran. You’ll notice no difference because scripts will all run synchronously anyway unless you explicitly force them to run parallel. I’d personally use module scripts so you can structure your project better. How fast your scripts run depend on how well you’ve optimized your scripts.

2 Likes

What I essentially did is requiring both Yield and Non-Yield, and those two require the modulescripts under them, now all of those modulescripts are placed into a dictionary when the require() is called with their name as the key. Yield is connected to a BindableFunction, while Non-Yield is connected to a BindableEvent, and both use the first argument as the modulescript’s name. They check if the modulescript’s name is present and call an uniform function called Execute(with args), so there’s no reuse of require() once it’s placed into a dictionary.

1 Like

So, technically speaking that’s not necessary since you can just run functions directly from modules, but you’re also indirectly de-coupling your scripts which is actually a good thing. You’re less likely to have things break elsewhere when you tweak a script as long as you ensure execute always takes the same arguments and returns the same values.

In my personal opinion it might be better to figure out a different way to get your modules rather than having a function to fetch them. You could have Yield return a table containing all of your required modules, for instance. That’d lead to less unnecessary function calls, since you’d just be indexing a dictionary directly instead of using a middleman each time.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.