SlideShare a Scribd company logo
DIVE INTO ANGULAR,
PART 3: PERFORMANCE
_by Oleksii Prohonnyi
AGENDA
 How to measure performance
 Watchers minimization
 Bind once
 Filters and cache
 Ng-Repeat
 Ng-Model
 Ng-If vs Ng-Show
 $$apply vs $$digest
 References
HOW TO MEASURE
PERFORMANCE
HOW TO MEASURE
PERFORMANCE
 Chrome Dev. Tools
 Batarang
 console.time
HOW TO MEASURE
PERFORMANCE: DEV.TOOLS
HOW TO MEASURE
PERFORMANCE: BATARANG
HOW TO MEASURE
PERFORMANCE: CONSOLE
WATCHERS MINIMIZATION
WATCHERS MINIMIZATION
 Angular uses dirty checking to keep track of all the changes in
app.
 This means it will have to go through every watcher to check if
they need to be updated (call the digest cycle).
 If one of the watcher is relied upon by another watcher, Angular
would have to re-run the digest cycle again, to make sure that all
of the changes has propagated.
 It will continue to do so, until all of the watchers have been
updated and app has stabilized.
WATCHERS MINIMIZATION
Watches are set on:
 $scope.$watch
 {{ }} type bindings
 Most directives (i.e. ng-show)
 Scope variables scope: { bar: '='}
 Filters {{ value | myFilter }}
 ng-repeat
WATCHERS MINIMIZATION
Watchers (digest cycle) run on:
 User action (ng-click etc). Most built in directives will call
$scope.apply upon completion which triggers the digest
cycle.
 ng-change
 ng-model
 $http events (so all ajax calls)
 $q promises resolved
 $timeout
 $interval
 Manual call to $scope.apply and $scope.digest
BIND ONCE
BIND ONCE
 Angular 1.3 added :: notation to allow one time binding.
 In summary, Angular will wait for a value to stabilize after it’s first
series of digest cycles, and will use that value to render the DOM
element.
 After that, Angular will remove the watcher forgetting about that
binding.
 See more: code.angularjs.org
FILTERS AND CACHE
FILTERS AND CACHE
 One time binding does not seem to play well with filters.
 There seems to be workarounds to make it work, but I think it’s
cleaner and more intuitive to simply assign the needed value to a
variable (or set it as a property on an object, if you are dealing
with a lot of variables).
 See more: code.angularjs.org
FILTERS AND CACHE
 Instead (HTML):
 Do (JavaScript):
 Do (HTML):
FILTERS AND CACHE
 Instead (HTML):
 Do (JavaScript):
 Do (HTML):
NG-REPEAT
NG-REPEAT
ngRepeat uses $watchCollection to detect changes in the
collection. When a change happens, ngRepeat then makes the
corresponding changes to the DOM:
 When an item is added, a new instance of the template is added
to the DOM.
 When an item is removed, its template instance is removed from
the DOM.
 When items are reordered, their respective templates are
reordered in the DOM.
 See more: code.angularjs.org
NG-MODEL
NG-MODEL
 If you know there is going to be a lot of changes coming from an
ng-model, you can de-bounce the input.
 For example if you have a search input like Google, you can de-
bounce it by setting the following ng-model option:
ng-model-options="{ debounce: 250 }.
 This will ensure that the digest cycle due to the changes in this
input model will get triggered no more then once per 250ms .
 See more: code.angularjs.org
NG-IF VS NG-SHOW
NG-IF VS NG-SHOW
 ng-show will render an element, and use display:none to
hide it,
 ng-if will actually removes the element from DOM, and will re-
create it, if it’s needed.
 You may need ng-show for an elements that toggles on an off
often, but for 95% of the time, ng-if is a better way to go.
 See more: docs.angularjs.org, docs.angularjs.org
$$APPLY VS $$DIGEST
$$APPLY VS $$DIGEST
 When $scope.$apply() is called, it kicks the entire
application into the $digest loop and in turn runs
$rootScope.$digest().
 This is what actually kicks off the internal $digest cycle.
 This cycle processes all of the watchers of the $scope it was
called from (and its children) until no more listeners can be fired.
 Instead of $scope.$apply, we could turn to
$scope.$digest, which runs the exact same $digest loop,
but is executed from the current $scope downwards through its
children, a much less costly venture.
 See more: binpress.com
REFERENCES
REFERENCES
 https://ng-perf.com/
 http://www.codelord.net/2014/06/17/angular-performance-101-
slides/
 http://www.alexkras.com/11-tips-to-improve-angularjs-
performance/
 https://medium.com/developers-writing/tips-and-practices-to-
optimize-your-angularjs-app-8118550ff808#.4vmopptk9
 http://blog.scalyr.com/2013/10/angularjs-1200ms-to-35ms/
 https://www.binpress.com/tutorial/speeding-up-angular-js-with-
simple-optimizations/135
 https://www.airpair.com/angularjs/posts/angularjs-performance-
large-applications
Dive into Angular, part 3: Performance
HOME TASK
HOME TASK
 Main idea: ruin performance of the application created after 2nd
meetup and optimize it using recommendations described above.
 Technical details:
– Update your application with more data, directives, DOM to
gather bad performance issues in it:
• at least 1000 rows in table on home page,
• at least 2000 watchers in the application.
– Optimize it using recommendations from today’s meeting.
 Download 2nd meetup’s application: github.com
Oleksii Prohonnyi
facebook.com/oprohonnyi
linkedin.com/in/oprohonnyi

More Related Content

PPTX
Dive into Angular, part 1: Introduction
PPTX
Dive into Angular, part 5: Experience
PPTX
Dive into Angular, part 2: Architecture
PPTX
Dive into Angular, part 4: Angular 2.0
PPTX
Code migration from Angular 1.x to Angular 2.0
PDF
React App State Management with react hooks and context api
PDF
Redux and context api with react native app introduction, use cases, implemen...
PPTX
Migrating an Application from Angular 1 to Angular 2
Dive into Angular, part 1: Introduction
Dive into Angular, part 5: Experience
Dive into Angular, part 2: Architecture
Dive into Angular, part 4: Angular 2.0
Code migration from Angular 1.x to Angular 2.0
React App State Management with react hooks and context api
Redux and context api with react native app introduction, use cases, implemen...
Migrating an Application from Angular 1 to Angular 2

What's hot (20)

PDF
Get rid of controllers in angular 1.5.x start using component directives
PDF
Angular from Scratch
PPTX
Migrating an application from Angular 1 to Angular 2
PPTX
Angular js
PDF
The productive developer guide to Angular 2
PPTX
Introduction to Angular js 2.0
PDF
Angular 2 - An Introduction
PDF
PDF
Building Universal Applications with Angular 2
PPTX
Angular 1.x vs 2 - In code level
PPTX
PPTX
Angular2 and You
ODP
Introduction to Angular 2
PPTX
Angular 4 - quick view
PDF
Data Flow Patterns in Angular 2 - Sebastian Müller
PPTX
AngularJS 2.0
PDF
AngularJS - Services
PPTX
Angular 9 New features
PPTX
Start your journey with angular | Basic Angular
PDF
Angular 2... so can I use it now??
Get rid of controllers in angular 1.5.x start using component directives
Angular from Scratch
Migrating an application from Angular 1 to Angular 2
Angular js
The productive developer guide to Angular 2
Introduction to Angular js 2.0
Angular 2 - An Introduction
Building Universal Applications with Angular 2
Angular 1.x vs 2 - In code level
Angular2 and You
Introduction to Angular 2
Angular 4 - quick view
Data Flow Patterns in Angular 2 - Sebastian Müller
AngularJS 2.0
AngularJS - Services
Angular 9 New features
Start your journey with angular | Basic Angular
Angular 2... so can I use it now??
Ad

Viewers also liked (18)

PPTX
Как создать сайт за 2 часа? (Wordpress)
PPT
Разработка веб-сайта. Сайт. Зачем он?
PPTX
Cycle.js overview
PPTX
Front-end rich JavaScript application creation (Backbone.js)
PPTX
Exploradores.caroes
PPTX
Conference DotJS 2015 Paris review
PPTX
Chorme devtools
PPTX
Moment.js overview
PPTX
Asm.js introduction
PPTX
Utility libraries to make your life easier
PPTX
OpenLayer's basics
PPTX
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
PPTX
Bower introduction
PDF
Chrome DevTools Awesome 10 Features +1
PPTX
Google Chrome DevTools features overview
PPTX
Introduction to D3.js
PPTX
JavaScript Presentation Frameworks and Libraries
PPTX
Code review process with JetBrains UpSource
Как создать сайт за 2 часа? (Wordpress)
Разработка веб-сайта. Сайт. Зачем он?
Cycle.js overview
Front-end rich JavaScript application creation (Backbone.js)
Exploradores.caroes
Conference DotJS 2015 Paris review
Chorme devtools
Moment.js overview
Asm.js introduction
Utility libraries to make your life easier
OpenLayer's basics
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
Bower introduction
Chrome DevTools Awesome 10 Features +1
Google Chrome DevTools features overview
Introduction to D3.js
JavaScript Presentation Frameworks and Libraries
Code review process with JetBrains UpSource
Ad

Similar to Dive into Angular, part 3: Performance (20)

PPTX
Angularjs Performance
PPTX
Scope demystified - AngularJS
PPTX
AngularJs presentation
PDF
AngularJS in practice
ODP
AngularJs Crash Course
PPTX
AngularJS Scopes
PDF
AngularJS Basics
PPT
Angular js meetup
PPT
angularjsmeetup-150303044616-conversion-gate01
PDF
Everything You Need To Know About AngularJS
PPTX
Understanding angular js
PPTX
AngularJS, More Than Directives !
PDF
Workshop 14: AngularJS Parte III
PPTX
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
PPTX
Optimizing a large angular application (ng conf)
PPTX
Angular js
PPTX
Angular workshop - Full Development Guide
PDF
AngularJS Beginner Day One
PDF
Art & music vs Google App Engine
PDF
Data binding in AngularJS, from model to view
Angularjs Performance
Scope demystified - AngularJS
AngularJs presentation
AngularJS in practice
AngularJs Crash Course
AngularJS Scopes
AngularJS Basics
Angular js meetup
angularjsmeetup-150303044616-conversion-gate01
Everything You Need To Know About AngularJS
Understanding angular js
AngularJS, More Than Directives !
Workshop 14: AngularJS Parte III
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
Optimizing a large angular application (ng conf)
Angular js
Angular workshop - Full Development Guide
AngularJS Beginner Day One
Art & music vs Google App Engine
Data binding in AngularJS, from model to view

More from Oleksii Prohonnyi (8)

PPTX
BEM methodology overview
PPTX
Front-end development introduction (JavaScript). Part 2
PPTX
Front-end development introduction (HTML, CSS). Part 1
PPTX
Test-driven development & Behavior-driven development basics
PPTX
JavaScript Coding Guidelines
PPTX
Database Optimization (MySQL)
PPTX
PHPCS (PHP Code Sniffer)
PPTX
Usability of UI Design (motivation, heuristics, tools)
BEM methodology overview
Front-end development introduction (JavaScript). Part 2
Front-end development introduction (HTML, CSS). Part 1
Test-driven development & Behavior-driven development basics
JavaScript Coding Guidelines
Database Optimization (MySQL)
PHPCS (PHP Code Sniffer)
Usability of UI Design (motivation, heuristics, tools)

Recently uploaded (20)

PDF
Understanding Forklifts - TECH EHS Solution
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
System and Network Administraation Chapter 3
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Essential Infomation Tech presentation.pptx
PPTX
ai tools demonstartion for schools and inter college
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Transform Your Business with a Software ERP System
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
top salesforce developer skills in 2025.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Understanding Forklifts - TECH EHS Solution
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
System and Network Administraation Chapter 3
Internet Downloader Manager (IDM) Crack 6.42 Build 41
VVF-Customer-Presentation2025-Ver1.9.pptx
Essential Infomation Tech presentation.pptx
ai tools demonstartion for schools and inter college
L1 - Introduction to python Backend.pptx
Transform Your Business with a Software ERP System
wealthsignaloriginal-com-DS-text-... (1).pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
top salesforce developer skills in 2025.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
2025 Textile ERP Trends: SAP, Odoo & Oracle
Softaken Excel to vCard Converter Software.pdf
Design an Analysis of Algorithms I-SECS-1021-03
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...

Dive into Angular, part 3: Performance

  • 1. DIVE INTO ANGULAR, PART 3: PERFORMANCE _by Oleksii Prohonnyi
  • 2. AGENDA  How to measure performance  Watchers minimization  Bind once  Filters and cache  Ng-Repeat  Ng-Model  Ng-If vs Ng-Show  $$apply vs $$digest  References
  • 4. HOW TO MEASURE PERFORMANCE  Chrome Dev. Tools  Batarang  console.time
  • 9. WATCHERS MINIMIZATION  Angular uses dirty checking to keep track of all the changes in app.  This means it will have to go through every watcher to check if they need to be updated (call the digest cycle).  If one of the watcher is relied upon by another watcher, Angular would have to re-run the digest cycle again, to make sure that all of the changes has propagated.  It will continue to do so, until all of the watchers have been updated and app has stabilized.
  • 10. WATCHERS MINIMIZATION Watches are set on:  $scope.$watch  {{ }} type bindings  Most directives (i.e. ng-show)  Scope variables scope: { bar: '='}  Filters {{ value | myFilter }}  ng-repeat
  • 11. WATCHERS MINIMIZATION Watchers (digest cycle) run on:  User action (ng-click etc). Most built in directives will call $scope.apply upon completion which triggers the digest cycle.  ng-change  ng-model  $http events (so all ajax calls)  $q promises resolved  $timeout  $interval  Manual call to $scope.apply and $scope.digest
  • 13. BIND ONCE  Angular 1.3 added :: notation to allow one time binding.  In summary, Angular will wait for a value to stabilize after it’s first series of digest cycles, and will use that value to render the DOM element.  After that, Angular will remove the watcher forgetting about that binding.  See more: code.angularjs.org
  • 15. FILTERS AND CACHE  One time binding does not seem to play well with filters.  There seems to be workarounds to make it work, but I think it’s cleaner and more intuitive to simply assign the needed value to a variable (or set it as a property on an object, if you are dealing with a lot of variables).  See more: code.angularjs.org
  • 16. FILTERS AND CACHE  Instead (HTML):  Do (JavaScript):  Do (HTML):
  • 17. FILTERS AND CACHE  Instead (HTML):  Do (JavaScript):  Do (HTML):
  • 19. NG-REPEAT ngRepeat uses $watchCollection to detect changes in the collection. When a change happens, ngRepeat then makes the corresponding changes to the DOM:  When an item is added, a new instance of the template is added to the DOM.  When an item is removed, its template instance is removed from the DOM.  When items are reordered, their respective templates are reordered in the DOM.  See more: code.angularjs.org
  • 21. NG-MODEL  If you know there is going to be a lot of changes coming from an ng-model, you can de-bounce the input.  For example if you have a search input like Google, you can de- bounce it by setting the following ng-model option: ng-model-options="{ debounce: 250 }.  This will ensure that the digest cycle due to the changes in this input model will get triggered no more then once per 250ms .  See more: code.angularjs.org
  • 23. NG-IF VS NG-SHOW  ng-show will render an element, and use display:none to hide it,  ng-if will actually removes the element from DOM, and will re- create it, if it’s needed.  You may need ng-show for an elements that toggles on an off often, but for 95% of the time, ng-if is a better way to go.  See more: docs.angularjs.org, docs.angularjs.org
  • 25. $$APPLY VS $$DIGEST  When $scope.$apply() is called, it kicks the entire application into the $digest loop and in turn runs $rootScope.$digest().  This is what actually kicks off the internal $digest cycle.  This cycle processes all of the watchers of the $scope it was called from (and its children) until no more listeners can be fired.  Instead of $scope.$apply, we could turn to $scope.$digest, which runs the exact same $digest loop, but is executed from the current $scope downwards through its children, a much less costly venture.  See more: binpress.com
  • 27. REFERENCES  https://ng-perf.com/  http://www.codelord.net/2014/06/17/angular-performance-101- slides/  http://www.alexkras.com/11-tips-to-improve-angularjs- performance/  https://medium.com/developers-writing/tips-and-practices-to- optimize-your-angularjs-app-8118550ff808#.4vmopptk9  http://blog.scalyr.com/2013/10/angularjs-1200ms-to-35ms/  https://www.binpress.com/tutorial/speeding-up-angular-js-with- simple-optimizations/135  https://www.airpair.com/angularjs/posts/angularjs-performance- large-applications
  • 30. HOME TASK  Main idea: ruin performance of the application created after 2nd meetup and optimize it using recommendations described above.  Technical details: – Update your application with more data, directives, DOM to gather bad performance issues in it: • at least 1000 rows in table on home page, • at least 2000 watchers in the application. – Optimize it using recommendations from today’s meeting.  Download 2nd meetup’s application: github.com