javascript - Batarang regularInterceptedExpression - Stack Overflow

I've been messing with the Batarang plugin recently to analyze some performance. I notice that at

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745329652a4622818.html

相关推荐

  • javascript - Batarang regularInterceptedExpression - Stack Overflow

    I've been messing with the Batarang plugin recently to analyze some performance. I notice that at

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信