javascript - Improve Angular 1.2 Tree Control performance -
i have app based on angular 1.2 not made me, huge 1 many developers work on it. , have bugs fix it. 1 it's improve angular tree control performance. big problem documentation poor directive. if work , have ideas, please let me know.
my understanding want learn how improve performance of angular 1.2 app. if correct, there several things might affect angular 1.x app performance:
- non-angular related issues - things memory management, critical rendering path etc. beyond scope of answer.
- angular related issues - comes down 2 factors: $digest cycles , $watchers.
in event, need measure before start optimizing. chrome dev tools great way that.
what should do?
- track load - use performance tab (a.k.a. timeline tab) in order record problematic scenarios. here's guide that: https://developers.google.com/web/tools/chrome-devtools/evaluate-performance/reference
- track how many times $digest runs , find source using easy script in browser. here's example of one. script finds slowest digests, can track them down , handle them. issue might actions trigger many digests. can track doing like:
$rootscope.$watch(function(){console.log('digest!')});
this print out digest! on every cycle. can add debug point there or use chrome's monitor capability , async stack trace find out initiated $digest cycle. play make more informative. instance:
var lastdigest = 0; var epsilon = 100; //ms - count close digests var count = 1; $rootscope.$watch(function(){ var currtime = new date().gettime(); if (currtime - lastdigest < epsilon) { count++; lastdigest = currtime; } else { console.log('digest! (' + count + ' found)'); count = 1; } }); in case above, you'll bunch digests came @ 100 ms period one, giving idea of how many digests action did. instance, if 1 click created 10 digests - it's cause alarm.
- track
$watchers- that's kind of easy in own app: bindings, explicit$watch/$watchcollectionstatements etc. here's nice article it. use 1 time binding (you'd have upgrade 1.3 - see here) or use 3rd party (1.2 compatible bind once).
that's basics. of course, suggest measuring app first, decide do. answer gave direction.
Comments
Post a Comment