0

In searching for potential bottlenecks in AngularJS I found this :

 var KEYWORD_REGEX = /^((ng:|[$_a-z])[\w\-_]+)/; 

src : https://github.com/angular/angular.js/blob/b77defde81fc265c13fa504dc78b41a43997abf4/docs/config/processors/keywords.js

KEYWORD_REGEX seems to have a high call count as it’s called within loop :

_.forEach(tokens, function(token) { (line 72)

Which itself is within an inner loop :

_.forEach(doc, function(value, key) { (line 97)

Which is also within an inner loop ! :

_.forEach(docs, function(doc) { (line 88)

Se we have a nested loop two layers deep : O(N)^3 performance

This question : How Do I Measure the Performance of my AngularJS app's digest Cycle? suggests cpu profile run using Chrome dev tools to measure performance, but I don't think is granular enough to measure the performance of a specific section of code.

I'm not sure what code to write in order to hit this file. From reading the commend of file keywords.js :

 * This processor extracts all the keywords from each document and creates
 * a new document that will be rendered as a JavaScript file containing all

It seems any angular enabled file should invoke keywords.js as angularjs scan's every document for directives ? To measure performance an approach is run AngularJS from source , modify the loops described above to include timings (using getTime() ) which measures each loop to complete, create many AngularJS directives and run the app ?

Community
  • 1
  • 1
thepen
  • 371
  • 1
  • 11
  • 1
    keywords.js doesn't belong to Angular sources. It isn't clear how it applies to the subject. – Estus Flask Dec 20 '16 at 11:22
  • @estus keywords.js is contained in https://github.com/angular/angular.js/search?utf8=%E2%9C%93&q=keywords.js&type=Code where https://github.com/angular/angular.js/ is the Angularjs source ? – thepen Dec 20 '16 at 11:45
  • angular/angular.js is project repo. Not just framework sources. The latter are in `src/`, according to the convention. The file you've cited is located at `/docs/config/processors`. It is Node script and obviously has relation to framework documentation, not the framework itself. – Estus Flask Dec 20 '16 at 11:50
  • @estus ah, a major oversight on my part, thanks. Do you know what the config project is utilized for as it still may be worth optimizing ? – thepen Dec 20 '16 at 12:06
  • It is likely used to generate Angular documentation. I'm quite sure that it has nothing to do with your question. Usually you may want to profile the app with dev tools and figure out bottlenecks from profiling results, not to guess them from source code. – Estus Flask Dec 20 '16 at 12:49
  • @estus agreed, but in this case O(N)^3 suggests poor performance unless N is quite small ? – thepen Dec 20 '16 at 14:02
  • Not necessarily. This totally depends on what O(N)^3 equals to. Nested loops aren't that bad by themselves. – Estus Flask Dec 20 '16 at 14:09

0 Answers0