大量模块会影响AngularJS的性能吗? [英] Does a large number of modules hit performance of AngularJS?

查看:116
本文介绍了大量模块会影响AngularJS的性能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以为此提供一些指示吗?

Could anyone provide some pointers on this?

说,我有很多服务模块,工厂模块等.并且我正在尝试构建一个有角度的大型应用程序,该应用程序具有在不同控制器下排列的大量html元素.

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.

推荐答案

我在angular文档中发现了以下语句:

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.

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

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.

因此,我认为,如果您包括成千上万个模块,则唯一的限制是浏览器保留了将其加载到脚本环境中的内存.我希望这是唯一的限制,因为我根本没有花任何时间研究js引擎如何实际执行此脚本加载.

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.

我创建了性能比较的初稿.这些测试用例在应用程序模块中包括none,100、1000和2000个模块.就目前而言,我看不到任何明显的性能差异! jsperf

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

这篇关于大量模块会影响AngularJS的性能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆