最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Batarang regularInterceptedExpression - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question asked May 23, 2016 at 19:51 Zack HerbertZack Herbert 9601 gold badge16 silver badges40 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

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.

发布评论

评论列表(0)

  1. 暂无评论