Mastering Web Application

(Rick Simeone) #1

Writing Robust AngularJS Web Applications


Running time of a $digest loop is proportional to number of watches and their
execution time. We can speed up the $digest loop both by limiting number of
watches or making them run faster. We can also enter the loop less frequently.


Memory consumption is another aspect of the overall performance that should be
monitored. In AngularJS-specific code precious memory bytes can be consumed by
deep-watches. We should avoid them as much as possible, not only when creating
watches manually (scope.$watch), but we should also make sure that we don't
create them accidently in templates.


The ng-repeat directive is especially performance-sensitive, both in terms of CPU
utilization and memory consumption. It might easily create a performance hotspot
if applied to a collection of several hundred items. To make, most of the ng-repeat
directive you need to keep source collections small by pre-filtering them. If you need
to display collections of several hundreds of elements you might consider writing
your own directive that would be fine-tuned for your particular use-case.


The next chapter is going to illustrate how to prepare a fine-tuned application for the
production deployment. It will also discuss network-related performance patterns.

Free download pdf