Reputation: 960
I've been messing with the Batarang plugin recently to analyze some performance. I notice that at the top of every log there is a section dedicated to something called regularInterceptedExpression. Can anybody explain what this means and what are some ways to improve the performance. I read somewhere that is could be from using the '=' property in directives. If anyone else has seen this, is there a solution?
Upvotes: 3
Views: 1551
Reputation: 828
If you dig into AngularJS code, you can see function regularInterceptedExpression(scope, locals, assign, inputs)
defined inside functionaddInterceptor(parsedExpression, interceptorFn)
. The only place where function addInterceptor(parsedExpression, interceptorFn)
is used is function $parse(exp, interceptorFn, expensiveChecks)
. This is where the String and other watches are converted to functions. You need to update the angular.js
file to
1) enhance the $parse(exp, interceptorFn, expensiveChecks)
function to keep the source of the parsing:
Find the end of the method and each switch case end update with setting the $$source
to the first argument of addInterceptor
function.
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);
2) inside the regularInterceptedExpression
function collect the statistics of
calls to that function:
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);
3) run you application and inspect the statistics i.e. open the Development Tools and write $$rieStats
into the JavaScript console. You should see the numbers of watchers being called by the regularInterceptedExpression
function.
Object.keys($$rieStats).sort(function(a,b){return $$rieStats[a]-$$rieStats[b]}).reverse().forEach(function(item){ console.log(item, $$rieStats[item])})
HINT: you can also add the $$rieStats
counting to the other branch function oneTimeInterceptedExpression
to track to one time binding as well.
Upvotes: 10