Reputation: 4102
Could anyone provide some pointers on this?
Say, I have a number of service modules, factory modules, etc.. and am trying to build a large app in angular that has a large number of html elements which are arranged under different controllers.
Now if I keep including these service/factory modules into my controllers as dependencies (I add them as a dependency since I may need them anytime); could that hit the performance of my app? Should only the used modules be included to avoid some kind of an overhead?
Surfing around hasn't really helped much to build a clear insight.
Upvotes: 8
Views: 1668
Reputation: 5048
I found the following statements in angular docs:
http://docs.angularjs.org/guide/module
Dependencies Modules can list other modules as their dependencies. Depending on a module implies that required module needs to be loaded before the requiring module is loaded. In other words the configuration blocks of the required modules execute before the configuration blocks of the requiring module. The same is true for the run blocks. Each module can only be loaded once, even if multiple other modules require it.
Asynchronous Loading Modules are a way of managing $injector configuration, and have nothing to do with loading of scripts into a VM. There are existing projects which deal with script loading, which may be used with Angular. Because modules do nothing at load time they can be loaded into the VM in any order and thus script loaders can take advantage of this property and parallelize the loading process.
So I think, if you include thousands of modules, the only limitation is the browser's memory reserved to load them into the script environment. I hope this is the only limitation because I did not spend any time at all to look into js engine how they actually do this scriptloading.
I created a first draft of a performance comparison. These test cases include none, 100, 1000 and 2000 modules into the app module. As for now I cannot see any significant performance difference! jsperf
Upvotes: 10