Zac*_*ert 2 javascript performance batarang
我最近一直在搞乱Batarang插件来分析一些性能.我注意到在每个日志的顶部都有一个专门用于名为regularInterceptedExpression的部分.任何人都可以解释这意味着什么以及提高性能的方法有哪些.我读到的地方可能是在指令中使用'='属性.如果有其他人看到这个,有解决方案吗?
如果深入研究AngularJS代码,可以看到函数regularInterceptedExpression(scope, locals, assign, inputs)内部定义的函数addInterceptor(parsedExpression, interceptorFn).功能addInterceptor(parsedExpression, interceptorFn)使用的唯一地方是功能$parse(exp, interceptorFn, expensiveChecks).这是String和其他手表转换为功能的地方.您需要将angular.js文件更新为
1)增强$parse(exp, interceptorFn, expensiveChecks)保持解析源的功能:
通过设置函数$$source的第一个参数,找到方法的结尾和每个开关案例结束更新addInterceptor.
parsedExpression.$$source = exp; // keep the source expression handy
return addInterceptor(parsedExpression, interceptorFn);
case 'function':
exp.$$source = exp; // keep the source expression handy
return addInterceptor(exp, interceptorFn);
default:
noop.$$source = exp; // keep the source expression handy
return addInterceptor(noop, interceptorFn);
Run Code Online (Sandbox Code Playgroud)
2)regularInterceptedExpression函数内部收集对该函数的调用统计信息:
var fn = regularWatch ? function regularInterceptedExpression(scope, locals, assign, inputs) {
var value = useInputs && inputs ? inputs[0] : parsedExpression(scope, locals, assign, inputs);
window.$$rieStats = window.$$rieStats || {};
window.$$rieStats[parsedExpression.$$source] = (window.$$rieStats[parsedExpression.$$source] ? window.$$rieStats[parsedExpression.$$source] : 0) + 1;
return interceptorFn(value, scope, locals);
Run Code Online (Sandbox Code Playgroud)
3)运行应用程序并检查统计信息,即打开开发工具并写入$$rieStatsJavaScript控制台.您应该看到该regularInterceptedExpression函数调用的观察者数量.
Object.keys($$rieStats).sort(function(a,b){return $$rieStats[a]-$$rieStats[b]}).reverse().forEach(function(item){ console.log(item, $$rieStats[item])})
Run Code Online (Sandbox Code Playgroud)
提示:您还可以将$$rieStats计数添加到其他分支函数oneTimeInterceptedExpression以跟踪到一个时间绑定.