Module loading times & Optimizations

Hello everyone! I was checking my module loading times and I want to know what you guys think. Before starting I must note that this module is not a single module but a huge collection and has multiple classes, I am telling you this so you know which lenses to judge with.

First of all Initializing the module takes this much time:
0.24321169999893755 sec

It is worth noting that this is because of a feature that this module has. It has a setting that allows for modules to link to each other and because of this; it waits a significant amount of time to link with other scripts. If I remove this feature by changing the setting to make it not attempt to link the module, the loading time reduces drastically to:
0.000008499999239575118 sec

The purpose of this “Link” is for cross-script communication. For instance, if I have script1 & script2 I can do this:

--Script1
local Core = module:Require("Core");
Core.customvalue = true;

--Script2
local Core = module:Require("Core");
print(Core.customvalue); --Prints true

Now, regarding actually requiring the stuff: If I require all the modules at the same time the amount it takes is:
0.05696000000170898 sec

However,

this module also has an improving feature, much like nodejs this module has cache and only requires the module once. Because of this if I want to require all the modules again it will only take:
0.000026887000276474283 sec

If you remove this cache the module will crash if you attempt to require all the things at once, this is because with no cache every mention of the module needs to be re-required. For instance, if I require EventEmitter (which is a class) EventEmitter needs to require:

  • proxy
    • table
  • table
    • proxy
  • math
    • table
  • string
    • table

  • Class
    • proxy
      • table
    • table
      • proxy
    • math
      • table
    • string
      • table

  • Enum
    • Class
      • proxy
        • table
      • table
        • proxy
      • math
        • table
      • string
        • table

etc…

To counter this I made a setting called “Primary Cache” which caches everything that isn’t being required primarily. This means that if you don’t want to cache the modules you can do so. In the script I require “EventEmitter” then “EventEmitter” would be a new instance but “Class” and the services “EventEmitter” uses will be a re-used instance only shared internally.

So I want to know what you guys think. I am asking you because I personally am really concerned with all the requiring that is going on. I do believe that the cache is a good solution for this, but I still want to know what you guys think about it.

  • Wonderfully optimized
  • Optimized
  • Needs some work but it is fine
  • Needs some serious work
  • Horribly optimized

0 voters

It’s very optimized, no real need to modify anything.

I’ve made a similar system before, but it cached modules marked as dependencies immediately upon initialization, and they were available to anything that wanted that dependency.

Structure was roughly:

  • ROOT Module | Top level
    • Standalone | No dependencies
    • Utilities | Depends on standalones
    • Classes | Typically uses Utilities and Standalone
    • Services | Uses Classes/Utilities/Standalone
    • Linker Layer | Links modules that may need to interact
      • Services | Services are initialized with the “FinishedLinking” signal
      • Runners | Initializes high level modules that use all previous types
    • FinishedLinking Fired | Signals Services to Start; also allows Runners to begin.

Anyways, I digress, it’s a good system.

1 Like