大量模块是否会影响AngularJS的性能?

时间:2021-09-18 16:54:37

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.

说,我有许多服务模块,工厂模块等。我正在尝试构建一个角度大的应用程序,它具有大量的html元素,这些元素排列在不同的控制器下。

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.

周围的冲浪并没有真正帮助建立一个清晰的洞察力。

1 个解决方案

#1


10  

I found the following statements in angular docs:

我在angular docs中找到了以下语句:

http://docs.angularjs.org/guide/module

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.

异步加载模块是一种管理$ injector配置的方法,与将脚本加载到VM无关。现有的项目处理脚本加载,可以与Angular一起使用。由于模块在加载时不执行任何操作,因此可以按任何顺序将其加载到VM中,因此脚本加载器可以利用此属性并并行化加载过程。

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.

所以我认为,如果你包含数千个模块,唯一的限制是保留浏览器的内存以将它们加载到脚本环境中。我希望这是唯一的限制,因为我没有花时间去研究js引擎他们实际上是如何进行这个脚本加载的。

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

我创建了性能比较的初稿。这些测试用例包括app模块中的无,100,1000和2000模块。至于现在,我看不出任何显着的性能差异! jsperf

#1


10  

I found the following statements in angular docs:

我在angular docs中找到了以下语句:

http://docs.angularjs.org/guide/module

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.

异步加载模块是一种管理$ injector配置的方法,与将脚本加载到VM无关。现有的项目处理脚本加载,可以与Angular一起使用。由于模块在加载时不执行任何操作,因此可以按任何顺序将其加载到VM中,因此脚本加载器可以利用此属性并并行化加载过程。

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.

所以我认为,如果你包含数千个模块,唯一的限制是保留浏览器的内存以将它们加载到脚本环境中。我希望这是唯一的限制,因为我没有花时间去研究js引擎他们实际上是如何进行这个脚本加载的。

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

我创建了性能比较的初稿。这些测试用例包括app模块中的无,100,1000和2000模块。至于现在,我看不出任何显着的性能差异! jsperf