Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a large number of modules hit performance of AngularJS?

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.

like image 802
5122014009 Avatar asked Jan 08 '14 12:01

5122014009


People also ask

Can we have multiple modules in AngularJS?

Yes, you can define multiple modules in angularJS as given below. The modularization in AngularJS helps us to keep the code clarity and easy to understand, as we can combine multiple modules to generate the application.

What is module in AngularJS?

An AngularJS module defines an application. The module is a container for the different parts of an application. The module is a container for the application controllers. Controllers always belong to a module.

What is AngularJS used for?

AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. AngularJS's data binding and dependency injection eliminate much of the code you would otherwise have to write.


1 Answers

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

like image 152
angabriel Avatar answered Sep 24 '22 13:09

angabriel