performance - 大量模块会影响 AngularJS 的性能吗?

标签 performance angularjs

任何人都可以提供一些指示吗?

比如说,我有许多服务模块、工厂模块等。我正在尝试构建一个大型应用程序,它有大量的 html 元素,这些元素排列在不同的 Controller 下。

现在,如果我继续将这些服务/工厂模块作为依赖项包含到我的 Controller 中(我将它们添加为依赖项,因为我可能随时需要它们);这会影响我的应用程序的性能吗?是否应该只包含使用过的模块以避免某种开销?

四处冲浪并没有真正帮助建立清晰的洞察力。

最佳答案

我在 Angular 文档中找到了以下语句:

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.



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

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

关于performance - 大量模块会影响 AngularJS 的性能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20995605/

相关文章:

javascript - 如何取消使用 angucomplete-alt remote-api-handler 发出的请求?

angularjs - 启动 angular.bootstrap 后取消引导?

javascript - 为什么 ngRepeat 没有按预期生成有序列表?

c - C 中的 float_fast(类似于 stdint.h 中的 int_fast)

javascript - 提高 Angular 性能: change the view to reactjs or Mithril?

正则表达式性能 : validating alphanumeric characters

带有 angularJS 应用程序的 ASP.NET MVC 区域

Java:创建 LinkedList 并将其转换为 ArrayList 进行排序是否有意义?

python-3.x - python 性能改进

javascript - 在 jQuery 动画之后绑定(bind) Angular 数据