分析/改进AngularJS的性能

时间:2016-12-20 11:19:14

标签: javascript angularjs performance

在搜索AngularJS中的潜在瓶颈时,我发现了这个:

 var KEYWORD_REGEX = /^((ng:|[$_a-z])[\w\-_]+)/; 

src: https://github.com/angular/angular.js/blob/b77defde81fc265c13fa504dc78b41a43997abf4/docs/config/processors/keywords.js

KEYWORD_REGEX似乎有一个很高的调用次数,因为它在循环中被调用:

_.forEach(tokens, function(token) { (line 72)

它本身就属于内循环:

_.forEach(doc, function(value, key) { (line 97)

哪个也在内循环中! :

_.forEach(docs, function(doc) { (line 88)

我们有一个深层两层的嵌套循环:O(N)^ 3性能

这个问题:How Do I Measure the Performance of my AngularJS app's digest Cycle?建议使用Chrome开发工具运行cpu配置文件以衡量性能,但我认为不够精确,无法衡量特定代码段的性能。

我不确定要写入哪个代码才能点击此文件。从阅读文件keywords.js的推荐:

 * This processor extracts all the keywords from each document and creates
 * a new document that will be rendered as a JavaScript file containing all

似乎任何启用角度的文件都应该调用keywords.js作为angularjs扫描指令的每个文档?为了测量性能,一个方法是从源代码运行AngularJS,修改上面描述的循环以包括时序(使用getTime())来测量每个循环来完成,创建许多AngularJS指令并运行应用程序?

0 个答案:

没有答案