【问题标题】:Batarang regularInterceptedExpressionBatarang 正则拦截表达式
【发布时间】:2016-09-20 19:52:39
【问题描述】:

我最近一直在弄乱 Batarang 插件来分析一些性能。我注意到在每个日志的顶部都有一个专门用于称为regularInterceptedExpression 的部分。任何人都可以解释这意味着什么以及提高性能的一些方法。我在某处读到可能来自在指令中使用“=”属性的地方。如果其他人看到了这个,有没有解决方案?

【问题讨论】:

    标签: javascript performance batarang


    【解决方案1】:

    如果您深入研究 AngularJS 代码,您可以看到在 functionaddInterceptor(parsedExpression, interceptorFn) 中定义的函数 regularInterceptedExpression(scope, locals, assign, inputs)。唯一使用函数addInterceptor(parsedExpression, interceptorFn) 的地方是函数$parse(exp, interceptorFn, expensiveChecks)。这是字符串和其他手表转换为函数的地方。您需要将angular.js 文件更新为

    1)增强$parse(exp, interceptorFn, expensiveChecks)函数,保留解析源:

    通过将$$source 设置为addInterceptor 函数的第一个参数来查找方法的结尾和每个switch case 的结尾更新。

          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)在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);
    

    3) 运行您的应用程序并检查统计信息,即打开开发工具并将$$rieStats 写入 JavaScript 控制台。您应该会看到 regularInterceptedExpression 函数调用的观察者数量。

    Object.keys($$rieStats).sort(function(a,b){return $$rieStats[a]-$$rieStats[b]}).reverse().forEach(function(item){ console.log(item, $$rieStats[item])})
    

    提示:您还可以将$$rieStats 计数添加到另一个分支函数oneTimeInterceptedExpression 以跟踪一次绑定。

    【讨论】:

      猜你喜欢
      • 2014-12-09
      • 2014-12-09
      • 1970-01-01
      • 2022-07-06
      • 2015-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多