SlideShare a Scribd company logo
AngularJS.
Performance &
Limits.
Dragos Rusu - CodeCamp Iasi 2014
(dragos.rusu@bytex.ro)
Our story
From
"We have to rethink this whole module, remove time navigation... it's just too sluggish." ★
to
"It's awesome, really fast, it's like going from night to day!" ★
(★) SOFTVISION customer
A few words about me
Dragos Rusu @ SOFTVISION
WEB/ZEND ENGINEER since 2007 (backend, frontend)
ARTICLE WRITER (PHP Architect)
PROJECTS: platforms for airlines (Cathay Pacific, Singapore Airlines, Air Berlin), tourism agencies,
home automation and security, agriculture
We will discuss about...
1. View watches / data bindings
2. What you see is what you show
3. The risk of polluting scopes
4. Core directives to avoid
5. Splitting the page
6. Miscellaneous
7. Limits
Q / A
disclaimer
PERFORMANCE principles for heavy apps (+500 man days)
* many items are not covered here.
* code samples - only in AngularJS
never used AngularJS before? no problem, principles are general, yet the solutions are particular.
Shall we?
1. View watches / data bindings
GENERAL CONTEXT
"more of 2000 watchers can lag the UI" (angular-tips.com)
"the expressions in curly braces denote bindings" ({{ ... }}) (docs.angularjs.org)
"AngularJS internally creates a $watch for each ng-* directive" (github.com/Pasvaz/bindonce)
"ngRepeat directive instantiates a template once per item [...] each template instance gets its own
scope" (docs.angularjs.org)
Ok... but why would I be counting watches?
AngularJS - Overcoming performance issues. Limits.
Every watcher is run at the digest cycle. The digest cycle is repeated until none of the results has
changed value
(Brian Ford - AngularJS contributor)
✈ A peak into AngularJS source code
$apply:function(expr){
try{
beginPhase('$apply');
returnthis.$eval(expr);
}catch(e){$exceptionHandler(e);
}finally{
clearPhase();
try{
$rootScope.$digest();//Ouhmy...
//[...]
?
https://github.com/angular/angular.js/blob/
master/src/ng/rootScope.js#L943
AngularJS - Overcoming performance issues. Limits.
AngularJS - Overcoming performance issues. Limits.
AngularJS - Overcoming performance issues. Limits.
AngularJS - Overcoming performance issues. Limits.
(1) double-binding creates tons of listeners
SOLUTION:
Whenever feasible, use single-binding solutions
double binding DEMO / bindonce DEMO
Why? Is double-binding slow?
Not quite. The AngularJS way of implementing it is slow ($dirty flags instead of observable
properties).
pssst: ECMA6: Object.observe()
github.com/Pasvaz/bindonce
github.com/kseamon/fast-bind
pssst: bindonce will be part of AngularJS 1.3 release!
(2) direct function calls from templates are called very often
SOLUTION: pre-compute the values to shown in the view model (default values, totals, etc)
<ul>
<ling-repeat="iteminitems">
//{{item.name}}({{computeTotal(item)}})
{{item.name}}({{item.computedTotal}})
</li>
</ul>
?
EXAMPLE
vatTotal will be recomputed on each scope $digest, regardless if the values that vatTotal() depend on
are changed or not (DEMO)
//...controller...
$scope.vat=24;//%
$scope.vatTotal=function(){
return(
$scope.data.item.total*
(1+$scope.vat/100)
);
};
//...template...
{{vatTotal()}}
?
(3) iterating over large data sets slows down the page
SOLUTION: create a lightweight iterable view model
angular.module('codecamp').controller('testCtrl',[
'$scope','dm','$q',function($scope,dm,$q){
'usestrict';
$scope._init=function(){
$scope.testViewModel={};
$q.all([dm.getData1(),dm.getData2()])
.then(function(response){
$scope.computeViewModel(response.data);
}
);
};
$scope._init();
}
);
?
(4) ng-repeat extra DOM manipulations
SOLUTION: ng-repeat with track by id (DEMO)
<ul>
<ling-repeat="iteminitemstrackbyitem.id">
{{item.name}}
</li>
</ul>
?
(5) filters are called very often
SOLUTION: lightweight quasi-independent filters
<span>{{value}}</span>
<ul>
<ling-repeat="iteminitems">
{{item.name|heavyFilteritem.value,$index}}
</li>
</ul>
?
WARNING: avoid touching DOM in filters and watches
(6) multiple recursive $watch might cause page flickering
SOLUTION: try to avoid recursive watch, where feasible
$scope.$watch('model.items',
function(newValue,oldValue){
//dosmth
},recursive=true);
);
?
(7) direct DOM watch functions might slow down the page
SOLUTION: try to avoid complex valueExpression, where feasible (use the data model instead)
//DirectiveLINKfunction
link:function($scope,$el,$attrs){
$scope.$watch(
function(){return$el[0].childNodes.length;},
function(newValue,oldValue){}
);
}
?
SOURCE: stackoverflow.com/questions/21332671
1. View watches / data bindings
2. What you see is what you show
3. The risk of polluting scopes
4. Core directives to avoid
5. Splitting the page
6. Miscellaneous
7. Limits
2. What you see is what you show
ng-if vs. ng-show (1)
ng-hide and ng-show makes no speed difference (DEMO)
<ulng-hide="hideCondition">
<ling-repeat="iteminitems">
{{item.value}}
</li>
</ul>
?
ng-if vs. ng-show (2)
ng-if/ng-switch might make a difference on more content
(e.g. tabbed page)
<ulng-if="displayCondition">
//CONTENT
</ul>
?
* fewer bindings
* fewer linkers called at startup
remove non-visible elements in the scroll (1)
one easy way would be PAGINATION
doesn't always apply though...
remove non-visible elements in the scroll (2)
DISPLAY elements, but ONLY THE VISIBLE ones
known as the VIRTUAL/INFINITE SCROLLING problem
remove non-visible elements in the scroll (3)
usually occurs when large data sets need to be displayed
OpenSource solutions:
http://binarymuse.github.io/ngInfiniteScroll/
http://blog.stackfull.com/2013/02/AngularJS-virtual-scrolling-part-1/
DEMO / DEMO (with virtual scroll)
1. View watches / data bindings
2. What you see is what you show
3. The risk of polluting scopes
4. Core directives to avoid
5. Splitting the page
6. Miscellaneous
7. Limits
3. The risk of polluting scopes
✈ DOM / SCOPES
AngularJS - Overcoming performance issues. Limits.
AngularJS - Overcoming performance issues. Limits.
(1) relying on multiple $rootScope and appCtrl functions may slow down the $digest
SOLUTION: try to avoid polluting $rootScope/appCtrl/* scopes
angular.module('codecamp').service('appInit',[
'$rootScope',function($rootScope){
'usestrict';
$rootScope.computeStuff=function(){...};
$rootScope.getData=function(){...};
$rootScope.i18n=function(){...};
$rootScope.manageAppStates=function(){...};
$rootScope.manageFormatters=function(){...};
//...andsoforth
});
?
- dispatch to specialized services/factories/filters/*
... and have some privacy in all scopes
angular.module('codecamp').controller('testCtrl',[
'$scope',function($scope){
'usestrict';
$scope._privateMethod=function(){};
functionnotRecommended(){
//...
}
});
?
1. View watches / data bindings
2. What you see is what you show
3. The risk of polluting scopes
4. Core directives to avoid
5. Splitting the page
6. Miscellaneous
7. Limits
4. Core directives to avoid
ALL of them
... right
Remember what we've said earlier?
"more of 2000 watchers can lag the UI" (angular-tips.com)
varngEventDirectives={};forEach(
'clickdblclickmousedownmouseupmouseoverblur
mouseoutmousemovemouseentermouseleavecopy
keydownkeyupkeypresssubmitfocuscutpaste'
.split(''),function(name){//[...]
returnfunction(scope,element,attr){//LINK
element.on(lowercase(name),function(event){
//scope.$apply=>$rootScope.$apply
scope.$apply(function(){
fn(scope,{$event:event});
});
//[...]
?
SOURCE: github.com/angular/angular.js/blob/
master/src/ng/directive/ngEventDirs.js#L41
AngularJS - Overcoming performance issues. Limits.
Does that really matter?
video not displayable
Quad core, 8 GB of RAM, Win7
Seems so...
video not displayable
SOLUTION: write custom directive(s), catch the events you need and...
.directive('customMouseEnter',[
function(){
'usestrict';
return{
restrict:'A',
link:function(scope,elem,attrs){
varfName=attrs.customMouseEnter,
func=function(ev){
scope[fName](ev);
};
elem.on('mouseenter',func);
scope.$on('$destroy',function(){
elem.off('mouseenter',func);
});
//[...]
?
...trigger local $digests (DEMO $digest over $apply)
//TEMPLATE
<trcustom-mouse-enter="ctrlMouseLeave">
//CONTROLLER/DIRECTIVE
scope.mouseLeave=function(ev){
//highlight,etc
//$digest()onlyonthescopeyouneed
scope.$digest();
};
?
Seems to be pretty common in the community
http://stackoverflow.com/questions/18421732/angularjs-how-to-override-directive-ngclick
http://briantford.com/blog/angular-hacking-core
(★) if you actually override default directives, remember to set a higher priority
1. View watches / data bindings
2. What you see is what you show
3. The risk of polluting scopes
4. Core directives to avoid
5. Splitting the page
6. Miscellaneous
7. Limits
5. Splitting the page
identify what is shareable and what is not
avoid splitting the page in too many sub-components
design your components in a blackbox manner
1. View watches / data bindings
2. What you see is what you show
3. The risk of polluting scopes
4. Core directives to avoid
5. Splitting the page
6. Miscellaneous
7. Limits
6. Miscenallaneous
(1) evalAsync(f) over $timeout(f)
More: http://www.bennadel.com/blog/2605-scope-evalasync-vs-timeout-in-angularjs.htm
(2) Watch out for external components performance and their usage
We had a problem with Moment.JS library (20% of the page load time, according to Chrome
Profiler)
(3) $eval your code from time to time - PERF wise
Batarang (identify $watchers), Chrome Profiler (memory, performance), performance.now()
(BONUS) demythify events
$emit / $broadcast (1)
SOURCE: jsperf.com/rootscope-emit-vs-rootscope-broadcast/24
$emit / $broadcast (2)
SOURCE: jsperf.com/rootscope-emit-vs-rootscope-broadcast/25
Ok... but why?
AngularJS 1.2.6 and below ▶ 12-15x difference
AngularJS 1.2.7+ ▶ 1.1x difference
"limit propagation of $broadcast to scopes that have listeners for the event"
(github.com/angular/angular.js/blob/master/CHANGELOG.md#performance-improvements-3)
RECAP: Common sense still says we should use them according to their design
1. View watches / data bindings
2. What you see is what you show
3. The risk of polluting scopes
4. Core directives to avoid
5. Splitting the page
6. Miscellaneous
7. Limits
7. Limits
"you quickly reach the end of what Angular can do for you when it comes to structuring
applications, at which point the community fragments transform to best practices, and few people
have figured out how to write large-scale Angular apps" (EmberJS core member)
Technical limits
1. + 2.000 dynamic elements on the screen
2. + 3.000 watchers
3. real time apps, where data changes very often
(★) depending on the device
Some apps examples:
stocks exchange
google maps
office apps
OUTPUT: screen flickering, low UX, unresponsive screens
And there's nothing you can do about it... except rewriting it in a lightweight framework
1. View watches / data bindings
2. What you see is what you show
3. The risk of polluting scopes
4. Core directives to avoid
5. Splitting the page
6. Miscellaneous
7. Limits
Recap? (1)
(1) be aware of too many data bindings (bindonce)
(2) try to minimize the number of $digest cycles
(3) have pre-computed values at template level
(4) display only the visible elements (virtual scroll)
Recap? (2)
(5) be aware of core directives PERF problems
(6) don't pollute your scopes and make them TDD friendly
(7) watch out for external components (angular or non-angular) performance
What's next?
it's a good habit to think PERF (pre-$compile the code in your head)
don't assume the frameworks are fast, whatever you may write
watch out for memory leaks
REMINDER: AngularJS is quite easy, just try it!
... and last but not least important: find a company that would allow you to grow your skills!
Q / A

More Related Content

What's hot (20)

AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practices
Henry Tao
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
Keith Bloomfield
 
Angular Best Practices v2
Angular Best Practices v2Angular Best Practices v2
Angular Best Practices v2
Henry Tao
 
Using ReactJS in AngularJS
Using ReactJS in AngularJSUsing ReactJS in AngularJS
Using ReactJS in AngularJS
Boris Dinkevich
 
Angularjs
AngularjsAngularjs
Angularjs
Vincenzo Ferrari
 
Integrating Angular js & three.js
Integrating Angular js & three.jsIntegrating Angular js & three.js
Integrating Angular js & three.js
Josh Staples
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)
Gary Arora
 
Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Angularjs - lazy loading techniques
Angularjs - lazy loading techniques
Nir Kaufman
 
Night Watch with QA
Night Watch with QANight Watch with QA
Night Watch with QA
Carsten Sandtner
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
Betclic Everest Group Tech Team
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
Jussi Pohjolainen
 
Testing frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTesting frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabs
Tudor Barbu
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
Manish Shekhawat
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
Gregor Woiwode
 
Angular js architecture (v1.4.8)
Angular js architecture (v1.4.8)Angular js architecture (v1.4.8)
Angular js architecture (v1.4.8)
Gabi Costel Lapusneanu
 
AngularJS Project Setup step-by- step guide - RapidValue Solutions
AngularJS Project Setup step-by- step guide - RapidValue SolutionsAngularJS Project Setup step-by- step guide - RapidValue Solutions
AngularJS Project Setup step-by- step guide - RapidValue Solutions
RapidValue
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
Phan Tuan
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
VO Tho
 
Angular 2 어디까지 왔을까
Angular 2 어디까지 왔을까Angular 2 어디까지 왔을까
Angular 2 어디까지 왔을까
장현 한
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
Sakthi Bro
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practices
Henry Tao
 
Angular Best Practices v2
Angular Best Practices v2Angular Best Practices v2
Angular Best Practices v2
Henry Tao
 
Using ReactJS in AngularJS
Using ReactJS in AngularJSUsing ReactJS in AngularJS
Using ReactJS in AngularJS
Boris Dinkevich
 
Integrating Angular js & three.js
Integrating Angular js & three.jsIntegrating Angular js & three.js
Integrating Angular js & three.js
Josh Staples
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)
Gary Arora
 
Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Angularjs - lazy loading techniques
Angularjs - lazy loading techniques
Nir Kaufman
 
Testing frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTesting frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabs
Tudor Barbu
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
Gregor Woiwode
 
AngularJS Project Setup step-by- step guide - RapidValue Solutions
AngularJS Project Setup step-by- step guide - RapidValue SolutionsAngularJS Project Setup step-by- step guide - RapidValue Solutions
AngularJS Project Setup step-by- step guide - RapidValue Solutions
RapidValue
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
Phan Tuan
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
VO Tho
 
Angular 2 어디까지 왔을까
Angular 2 어디까지 왔을까Angular 2 어디까지 왔을까
Angular 2 어디까지 왔을까
장현 한
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
Sakthi Bro
 

Viewers also liked (20)

29 Essential AngularJS Interview Questions
29 Essential AngularJS Interview Questions29 Essential AngularJS Interview Questions
29 Essential AngularJS Interview Questions
Arc & Codementor
 
Angular js - 10 reasons to choose angularjs
Angular js - 10 reasons to choose angularjs Angular js - 10 reasons to choose angularjs
Angular js - 10 reasons to choose angularjs
Nir Kaufman
 
AngularJS Ecosystem
AngularJS EcosystemAngularJS Ecosystem
AngularJS Ecosystem
Vadim Tomnikov
 
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
Dimitar Danailov
 
Promises And Chaining In AngularJS - Into Callback Hell And Back Again
Promises And Chaining In AngularJS - Into Callback Hell And Back AgainPromises And Chaining In AngularJS - Into Callback Hell And Back Again
Promises And Chaining In AngularJS - Into Callback Hell And Back Again
Hans-Gunther Schmidt
 
Bash Scripting
Bash ScriptingBash Scripting
Bash Scripting
Marian Marinov
 
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
JavaCro'14 - Unit testing in AngularJS – Slaven TomacJavaCro'14 - Unit testing in AngularJS – Slaven Tomac
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Bash Scripting
Bash ScriptingBash Scripting
Bash Scripting
Vincent Claes
 
Java9 moduulit jigsaw
Java9 moduulit jigsawJava9 moduulit jigsaw
Java9 moduulit jigsaw
Arto Santala
 
Angular2 with type script
Angular2 with type scriptAngular2 with type script
Angular2 with type script
Ravi Mone
 
JDK 9: Big Changes To Make Java Smaller
JDK 9: Big Changes To Make Java SmallerJDK 9: Big Changes To Make Java Smaller
JDK 9: Big Changes To Make Java Smaller
Simon Ritter
 
Finding and debugging memory leaks in JavaScript with Chrome DevTools
Finding and debugging memory leaks in JavaScript with Chrome DevToolsFinding and debugging memory leaks in JavaScript with Chrome DevTools
Finding and debugging memory leaks in JavaScript with Chrome DevTools
Gonzalo Ruiz de Villa
 
Why zsh is Cooler than Your Shell
Why zsh is Cooler than Your ShellWhy zsh is Cooler than Your Shell
Why zsh is Cooler than Your Shell
brendon_jag
 
shell script introduction
shell script introductionshell script introduction
shell script introduction
Jie Jin
 
Symfony2 and AngularJS
Symfony2 and AngularJSSymfony2 and AngularJS
Symfony2 and AngularJS
Antonio Peric-Mazar
 
자바9 특징 (Java9 Features)
자바9 특징 (Java9 Features)자바9 특징 (Java9 Features)
자바9 특징 (Java9 Features)
Chang-Hwan Han
 
Java9 특징 훑어보기
Java9 특징 훑어보기Java9 특징 훑어보기
Java9 특징 훑어보기
duriepark 유현석
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
Eyal Vardi
 
Shell and tube heat exchanger design
Shell and tube heat exchanger designShell and tube heat exchanger design
Shell and tube heat exchanger design
hossie
 
Why Zsh is Cooler than Your Shell
Why Zsh is Cooler than Your ShellWhy Zsh is Cooler than Your Shell
Why Zsh is Cooler than Your Shell
jaguardesignstudio
 
29 Essential AngularJS Interview Questions
29 Essential AngularJS Interview Questions29 Essential AngularJS Interview Questions
29 Essential AngularJS Interview Questions
Arc & Codementor
 
Angular js - 10 reasons to choose angularjs
Angular js - 10 reasons to choose angularjs Angular js - 10 reasons to choose angularjs
Angular js - 10 reasons to choose angularjs
Nir Kaufman
 
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
Dimitar Danailov
 
Promises And Chaining In AngularJS - Into Callback Hell And Back Again
Promises And Chaining In AngularJS - Into Callback Hell And Back AgainPromises And Chaining In AngularJS - Into Callback Hell And Back Again
Promises And Chaining In AngularJS - Into Callback Hell And Back Again
Hans-Gunther Schmidt
 
Java9 moduulit jigsaw
Java9 moduulit jigsawJava9 moduulit jigsaw
Java9 moduulit jigsaw
Arto Santala
 
Angular2 with type script
Angular2 with type scriptAngular2 with type script
Angular2 with type script
Ravi Mone
 
JDK 9: Big Changes To Make Java Smaller
JDK 9: Big Changes To Make Java SmallerJDK 9: Big Changes To Make Java Smaller
JDK 9: Big Changes To Make Java Smaller
Simon Ritter
 
Finding and debugging memory leaks in JavaScript with Chrome DevTools
Finding and debugging memory leaks in JavaScript with Chrome DevToolsFinding and debugging memory leaks in JavaScript with Chrome DevTools
Finding and debugging memory leaks in JavaScript with Chrome DevTools
Gonzalo Ruiz de Villa
 
Why zsh is Cooler than Your Shell
Why zsh is Cooler than Your ShellWhy zsh is Cooler than Your Shell
Why zsh is Cooler than Your Shell
brendon_jag
 
shell script introduction
shell script introductionshell script introduction
shell script introduction
Jie Jin
 
자바9 특징 (Java9 Features)
자바9 특징 (Java9 Features)자바9 특징 (Java9 Features)
자바9 특징 (Java9 Features)
Chang-Hwan Han
 
Java9 특징 훑어보기
Java9 특징 훑어보기Java9 특징 훑어보기
Java9 특징 훑어보기
duriepark 유현석
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
Eyal Vardi
 
Shell and tube heat exchanger design
Shell and tube heat exchanger designShell and tube heat exchanger design
Shell and tube heat exchanger design
hossie
 
Why Zsh is Cooler than Your Shell
Why Zsh is Cooler than Your ShellWhy Zsh is Cooler than Your Shell
Why Zsh is Cooler than Your Shell
jaguardesignstudio
 
Ad

Similar to AngularJS - Overcoming performance issues. Limits. (20)

Optimizing a large angular application (ng conf)
Optimizing a large angular application (ng conf)Optimizing a large angular application (ng conf)
Optimizing a large angular application (ng conf)
A K M Zahiduzzaman
 
Angular js meetup
Angular js meetupAngular js meetup
Angular js meetup
Pierre-Yves Gicquel
 
angularjsmeetup-150303044616-conversion-gate01
angularjsmeetup-150303044616-conversion-gate01angularjsmeetup-150303044616-conversion-gate01
angularjsmeetup-150303044616-conversion-gate01
Teo E
 
Optimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page AppsOptimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page Apps
Morgan Stone
 
Dive into Angular, part 3: Performance
Dive into Angular, part 3: PerformanceDive into Angular, part 3: Performance
Dive into Angular, part 3: Performance
Oleksii Prohonnyi
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
Narek Mamikonyan
 
Bhuvi ppt zerobug
Bhuvi ppt zerobugBhuvi ppt zerobug
Bhuvi ppt zerobug
BhuviS3
 
AngularJS (1.x) as fast as a lightning
AngularJS (1.x)as fast as a lightningAngularJS (1.x)as fast as a lightning
AngularJS (1.x) as fast as a lightning
Bartłomiej Narożnik
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
Duy Khanh
 
[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS
[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS
[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS
Srijan Technologies
 
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Alessandro Nadalin
 
Angular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd MottoAngular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd Motto
Future Insights
 
Optimizing AngularJS Application
Optimizing AngularJS ApplicationOptimizing AngularJS Application
Optimizing AngularJS Application
Md. Ziaul Haq
 
5 angularjs features
5 angularjs features5 angularjs features
5 angularjs features
Alexey (Mr_Mig) Migutsky
 
Working with AngularJS
Working with AngularJSWorking with AngularJS
Working with AngularJS
André Vala
 
AngularJS in practice
AngularJS in practiceAngularJS in practice
AngularJS in practice
Eugene Fidelin
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
Gianluca Cacace
 
Tips for Angular Applications
Tips for Angular ApplicationsTips for Angular Applications
Tips for Angular Applications
Sebastian Pederiva
 
AngularJS best practices
AngularJS best practicesAngularJS best practices
AngularJS best practices
Filip Bruun Bech-Larsen
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
Nitin Giri
 
Optimizing a large angular application (ng conf)
Optimizing a large angular application (ng conf)Optimizing a large angular application (ng conf)
Optimizing a large angular application (ng conf)
A K M Zahiduzzaman
 
angularjsmeetup-150303044616-conversion-gate01
angularjsmeetup-150303044616-conversion-gate01angularjsmeetup-150303044616-conversion-gate01
angularjsmeetup-150303044616-conversion-gate01
Teo E
 
Optimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page AppsOptimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page Apps
Morgan Stone
 
Dive into Angular, part 3: Performance
Dive into Angular, part 3: PerformanceDive into Angular, part 3: Performance
Dive into Angular, part 3: Performance
Oleksii Prohonnyi
 
Bhuvi ppt zerobug
Bhuvi ppt zerobugBhuvi ppt zerobug
Bhuvi ppt zerobug
BhuviS3
 
AngularJS (1.x) as fast as a lightning
AngularJS (1.x)as fast as a lightningAngularJS (1.x)as fast as a lightning
AngularJS (1.x) as fast as a lightning
Bartłomiej Narożnik
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
Duy Khanh
 
[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS
[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS
[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS
Srijan Technologies
 
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Alessandro Nadalin
 
Angular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd MottoAngular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd Motto
Future Insights
 
Optimizing AngularJS Application
Optimizing AngularJS ApplicationOptimizing AngularJS Application
Optimizing AngularJS Application
Md. Ziaul Haq
 
Working with AngularJS
Working with AngularJSWorking with AngularJS
Working with AngularJS
André Vala
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
Nitin Giri
 
Ad

Recently uploaded (20)

Intranet Examples That Are Changing the Way We Work
Intranet Examples That Are Changing the Way We WorkIntranet Examples That Are Changing the Way We Work
Intranet Examples That Are Changing the Way We Work
BizPortals Solutions
 
Shortcomings of EHS Software – And How to Overcome Them
Shortcomings of EHS Software – And How to Overcome ThemShortcomings of EHS Software – And How to Overcome Them
Shortcomings of EHS Software – And How to Overcome Them
TECH EHS Solution
 
Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!
PhilMeredith3
 
Internship in South western railways on software
Internship in South western railways on softwareInternship in South western railways on software
Internship in South western railways on software
abhim5889
 
Software Risk and Quality management.pptx
Software Risk and Quality management.pptxSoftware Risk and Quality management.pptx
Software Risk and Quality management.pptx
HassanBangash9
 
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
gauravvmanchandaa200
 
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
Nacho Cougil
 
Facility Management Solution - TeroTAM CMMS Software
Facility Management Solution - TeroTAM CMMS SoftwareFacility Management Solution - TeroTAM CMMS Software
Facility Management Solution - TeroTAM CMMS Software
TeroTAM
 
War Story: Removing Offensive Language from Percona Toolkit
War Story: Removing Offensive Language from Percona ToolkitWar Story: Removing Offensive Language from Percona Toolkit
War Story: Removing Offensive Language from Percona Toolkit
Sveta Smirnova
 
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjaraswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
muhammadalikhanalikh1
 
Issues in AI Presentation and machine learning.pptx
Issues in AI Presentation and machine learning.pptxIssues in AI Presentation and machine learning.pptx
Issues in AI Presentation and machine learning.pptx
Jalalkhan657136
 
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
officeiqai
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
Optimising Claims Management with Claims Processing Systems
Optimising Claims Management with Claims Processing SystemsOptimising Claims Management with Claims Processing Systems
Optimising Claims Management with Claims Processing Systems
Insurance Tech Services
 
SQL-COMMANDS instructionsssssssssss.pptx
SQL-COMMANDS instructionsssssssssss.pptxSQL-COMMANDS instructionsssssssssss.pptx
SQL-COMMANDS instructionsssssssssss.pptx
Ashlei5
 
Top 10 Mobile Banking Apps in the USA.pdf
Top 10 Mobile Banking Apps in the USA.pdfTop 10 Mobile Banking Apps in the USA.pdf
Top 10 Mobile Banking Apps in the USA.pdf
LL Technolab
 
Content Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ ProductivityContent Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ Productivity
Alex Vladimirovich
 
Oliveira2024 - Combining GPT and Weak Supervision.pdf
Oliveira2024 - Combining GPT and Weak Supervision.pdfOliveira2024 - Combining GPT and Weak Supervision.pdf
Oliveira2024 - Combining GPT and Weak Supervision.pdf
GiliardGodoi1
 
Topic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptxTopic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptx
marutnand8
 
Techdebt handling with cleancode focus and as risk taker
Techdebt handling with cleancode focus and as risk takerTechdebt handling with cleancode focus and as risk taker
Techdebt handling with cleancode focus and as risk taker
RajaNagendraKumar
 
Intranet Examples That Are Changing the Way We Work
Intranet Examples That Are Changing the Way We WorkIntranet Examples That Are Changing the Way We Work
Intranet Examples That Are Changing the Way We Work
BizPortals Solutions
 
Shortcomings of EHS Software – And How to Overcome Them
Shortcomings of EHS Software – And How to Overcome ThemShortcomings of EHS Software – And How to Overcome Them
Shortcomings of EHS Software – And How to Overcome Them
TECH EHS Solution
 
Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!
PhilMeredith3
 
Internship in South western railways on software
Internship in South western railways on softwareInternship in South western railways on software
Internship in South western railways on software
abhim5889
 
Software Risk and Quality management.pptx
Software Risk and Quality management.pptxSoftware Risk and Quality management.pptx
Software Risk and Quality management.pptx
HassanBangash9
 
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
gauravvmanchandaa200
 
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
Nacho Cougil
 
Facility Management Solution - TeroTAM CMMS Software
Facility Management Solution - TeroTAM CMMS SoftwareFacility Management Solution - TeroTAM CMMS Software
Facility Management Solution - TeroTAM CMMS Software
TeroTAM
 
War Story: Removing Offensive Language from Percona Toolkit
War Story: Removing Offensive Language from Percona ToolkitWar Story: Removing Offensive Language from Percona Toolkit
War Story: Removing Offensive Language from Percona Toolkit
Sveta Smirnova
 
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjaraswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
muhammadalikhanalikh1
 
Issues in AI Presentation and machine learning.pptx
Issues in AI Presentation and machine learning.pptxIssues in AI Presentation and machine learning.pptx
Issues in AI Presentation and machine learning.pptx
Jalalkhan657136
 
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
officeiqai
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
Optimising Claims Management with Claims Processing Systems
Optimising Claims Management with Claims Processing SystemsOptimising Claims Management with Claims Processing Systems
Optimising Claims Management with Claims Processing Systems
Insurance Tech Services
 
SQL-COMMANDS instructionsssssssssss.pptx
SQL-COMMANDS instructionsssssssssss.pptxSQL-COMMANDS instructionsssssssssss.pptx
SQL-COMMANDS instructionsssssssssss.pptx
Ashlei5
 
Top 10 Mobile Banking Apps in the USA.pdf
Top 10 Mobile Banking Apps in the USA.pdfTop 10 Mobile Banking Apps in the USA.pdf
Top 10 Mobile Banking Apps in the USA.pdf
LL Technolab
 
Content Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ ProductivityContent Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ Productivity
Alex Vladimirovich
 
Oliveira2024 - Combining GPT and Weak Supervision.pdf
Oliveira2024 - Combining GPT and Weak Supervision.pdfOliveira2024 - Combining GPT and Weak Supervision.pdf
Oliveira2024 - Combining GPT and Weak Supervision.pdf
GiliardGodoi1
 
Topic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptxTopic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptx
marutnand8
 
Techdebt handling with cleancode focus and as risk taker
Techdebt handling with cleancode focus and as risk takerTechdebt handling with cleancode focus and as risk taker
Techdebt handling with cleancode focus and as risk taker
RajaNagendraKumar
 

AngularJS - Overcoming performance issues. Limits.

  • 2. Our story From "We have to rethink this whole module, remove time navigation... it's just too sluggish." ★ to "It's awesome, really fast, it's like going from night to day!" ★ (★) SOFTVISION customer
  • 3. A few words about me Dragos Rusu @ SOFTVISION WEB/ZEND ENGINEER since 2007 (backend, frontend) ARTICLE WRITER (PHP Architect) PROJECTS: platforms for airlines (Cathay Pacific, Singapore Airlines, Air Berlin), tourism agencies, home automation and security, agriculture
  • 4. We will discuss about... 1. View watches / data bindings 2. What you see is what you show 3. The risk of polluting scopes 4. Core directives to avoid 5. Splitting the page 6. Miscellaneous 7. Limits Q / A
  • 5. disclaimer PERFORMANCE principles for heavy apps (+500 man days) * many items are not covered here. * code samples - only in AngularJS never used AngularJS before? no problem, principles are general, yet the solutions are particular.
  • 7. 1. View watches / data bindings
  • 8. GENERAL CONTEXT "more of 2000 watchers can lag the UI" (angular-tips.com) "the expressions in curly braces denote bindings" ({{ ... }}) (docs.angularjs.org) "AngularJS internally creates a $watch for each ng-* directive" (github.com/Pasvaz/bindonce) "ngRepeat directive instantiates a template once per item [...] each template instance gets its own scope" (docs.angularjs.org)
  • 9. Ok... but why would I be counting watches?
  • 11. Every watcher is run at the digest cycle. The digest cycle is repeated until none of the results has changed value (Brian Ford - AngularJS contributor)
  • 12. ✈ A peak into AngularJS source code $apply:function(expr){ try{ beginPhase('$apply'); returnthis.$eval(expr); }catch(e){$exceptionHandler(e); }finally{ clearPhase(); try{ $rootScope.$digest();//Ouhmy... //[...] ? https://github.com/angular/angular.js/blob/ master/src/ng/rootScope.js#L943
  • 17. (1) double-binding creates tons of listeners
  • 18. SOLUTION: Whenever feasible, use single-binding solutions double binding DEMO / bindonce DEMO
  • 19. Why? Is double-binding slow? Not quite. The AngularJS way of implementing it is slow ($dirty flags instead of observable properties). pssst: ECMA6: Object.observe()
  • 21. (2) direct function calls from templates are called very often SOLUTION: pre-compute the values to shown in the view model (default values, totals, etc) <ul> <ling-repeat="iteminitems"> //{{item.name}}({{computeTotal(item)}}) {{item.name}}({{item.computedTotal}}) </li> </ul> ?
  • 22. EXAMPLE vatTotal will be recomputed on each scope $digest, regardless if the values that vatTotal() depend on are changed or not (DEMO) //...controller... $scope.vat=24;//% $scope.vatTotal=function(){ return( $scope.data.item.total* (1+$scope.vat/100) ); }; //...template... {{vatTotal()}} ?
  • 23. (3) iterating over large data sets slows down the page SOLUTION: create a lightweight iterable view model angular.module('codecamp').controller('testCtrl',[ '$scope','dm','$q',function($scope,dm,$q){ 'usestrict'; $scope._init=function(){ $scope.testViewModel={}; $q.all([dm.getData1(),dm.getData2()]) .then(function(response){ $scope.computeViewModel(response.data); } ); }; $scope._init(); } ); ?
  • 24. (4) ng-repeat extra DOM manipulations SOLUTION: ng-repeat with track by id (DEMO) <ul> <ling-repeat="iteminitemstrackbyitem.id"> {{item.name}} </li> </ul> ?
  • 25. (5) filters are called very often SOLUTION: lightweight quasi-independent filters <span>{{value}}</span> <ul> <ling-repeat="iteminitems"> {{item.name|heavyFilteritem.value,$index}} </li> </ul> ? WARNING: avoid touching DOM in filters and watches
  • 26. (6) multiple recursive $watch might cause page flickering SOLUTION: try to avoid recursive watch, where feasible $scope.$watch('model.items', function(newValue,oldValue){ //dosmth },recursive=true); ); ?
  • 27. (7) direct DOM watch functions might slow down the page SOLUTION: try to avoid complex valueExpression, where feasible (use the data model instead) //DirectiveLINKfunction link:function($scope,$el,$attrs){ $scope.$watch( function(){return$el[0].childNodes.length;}, function(newValue,oldValue){} ); } ? SOURCE: stackoverflow.com/questions/21332671
  • 28. 1. View watches / data bindings 2. What you see is what you show 3. The risk of polluting scopes 4. Core directives to avoid 5. Splitting the page 6. Miscellaneous 7. Limits
  • 29. 2. What you see is what you show
  • 30. ng-if vs. ng-show (1) ng-hide and ng-show makes no speed difference (DEMO) <ulng-hide="hideCondition"> <ling-repeat="iteminitems"> {{item.value}} </li> </ul> ?
  • 31. ng-if vs. ng-show (2) ng-if/ng-switch might make a difference on more content (e.g. tabbed page) <ulng-if="displayCondition"> //CONTENT </ul> ? * fewer bindings * fewer linkers called at startup
  • 32. remove non-visible elements in the scroll (1) one easy way would be PAGINATION doesn't always apply though...
  • 33. remove non-visible elements in the scroll (2) DISPLAY elements, but ONLY THE VISIBLE ones known as the VIRTUAL/INFINITE SCROLLING problem
  • 34. remove non-visible elements in the scroll (3) usually occurs when large data sets need to be displayed OpenSource solutions: http://binarymuse.github.io/ngInfiniteScroll/ http://blog.stackfull.com/2013/02/AngularJS-virtual-scrolling-part-1/ DEMO / DEMO (with virtual scroll)
  • 35. 1. View watches / data bindings 2. What you see is what you show 3. The risk of polluting scopes 4. Core directives to avoid 5. Splitting the page 6. Miscellaneous 7. Limits
  • 36. 3. The risk of polluting scopes
  • 37. ✈ DOM / SCOPES
  • 40. (1) relying on multiple $rootScope and appCtrl functions may slow down the $digest SOLUTION: try to avoid polluting $rootScope/appCtrl/* scopes angular.module('codecamp').service('appInit',[ '$rootScope',function($rootScope){ 'usestrict'; $rootScope.computeStuff=function(){...}; $rootScope.getData=function(){...}; $rootScope.i18n=function(){...}; $rootScope.manageAppStates=function(){...}; $rootScope.manageFormatters=function(){...}; //...andsoforth }); ? - dispatch to specialized services/factories/filters/*
  • 41. ... and have some privacy in all scopes angular.module('codecamp').controller('testCtrl',[ '$scope',function($scope){ 'usestrict'; $scope._privateMethod=function(){}; functionnotRecommended(){ //... } }); ?
  • 42. 1. View watches / data bindings 2. What you see is what you show 3. The risk of polluting scopes 4. Core directives to avoid 5. Splitting the page 6. Miscellaneous 7. Limits
  • 43. 4. Core directives to avoid
  • 45. Remember what we've said earlier? "more of 2000 watchers can lag the UI" (angular-tips.com)
  • 48. Does that really matter? video not displayable Quad core, 8 GB of RAM, Win7
  • 49. Seems so... video not displayable
  • 50. SOLUTION: write custom directive(s), catch the events you need and... .directive('customMouseEnter',[ function(){ 'usestrict'; return{ restrict:'A', link:function(scope,elem,attrs){ varfName=attrs.customMouseEnter, func=function(ev){ scope[fName](ev); }; elem.on('mouseenter',func); scope.$on('$destroy',function(){ elem.off('mouseenter',func); }); //[...] ?
  • 51. ...trigger local $digests (DEMO $digest over $apply) //TEMPLATE <trcustom-mouse-enter="ctrlMouseLeave"> //CONTROLLER/DIRECTIVE scope.mouseLeave=function(ev){ //highlight,etc //$digest()onlyonthescopeyouneed scope.$digest(); }; ?
  • 52. Seems to be pretty common in the community http://stackoverflow.com/questions/18421732/angularjs-how-to-override-directive-ngclick http://briantford.com/blog/angular-hacking-core (★) if you actually override default directives, remember to set a higher priority
  • 53. 1. View watches / data bindings 2. What you see is what you show 3. The risk of polluting scopes 4. Core directives to avoid 5. Splitting the page 6. Miscellaneous 7. Limits
  • 55. identify what is shareable and what is not avoid splitting the page in too many sub-components design your components in a blackbox manner
  • 56. 1. View watches / data bindings 2. What you see is what you show 3. The risk of polluting scopes 4. Core directives to avoid 5. Splitting the page 6. Miscellaneous 7. Limits
  • 58. (1) evalAsync(f) over $timeout(f) More: http://www.bennadel.com/blog/2605-scope-evalasync-vs-timeout-in-angularjs.htm
  • 59. (2) Watch out for external components performance and their usage We had a problem with Moment.JS library (20% of the page load time, according to Chrome Profiler)
  • 60. (3) $eval your code from time to time - PERF wise Batarang (identify $watchers), Chrome Profiler (memory, performance), performance.now()
  • 62. $emit / $broadcast (1) SOURCE: jsperf.com/rootscope-emit-vs-rootscope-broadcast/24
  • 63. $emit / $broadcast (2) SOURCE: jsperf.com/rootscope-emit-vs-rootscope-broadcast/25
  • 64. Ok... but why? AngularJS 1.2.6 and below ▶ 12-15x difference AngularJS 1.2.7+ ▶ 1.1x difference "limit propagation of $broadcast to scopes that have listeners for the event" (github.com/angular/angular.js/blob/master/CHANGELOG.md#performance-improvements-3) RECAP: Common sense still says we should use them according to their design
  • 65. 1. View watches / data bindings 2. What you see is what you show 3. The risk of polluting scopes 4. Core directives to avoid 5. Splitting the page 6. Miscellaneous 7. Limits
  • 67. "you quickly reach the end of what Angular can do for you when it comes to structuring applications, at which point the community fragments transform to best practices, and few people have figured out how to write large-scale Angular apps" (EmberJS core member)
  • 68. Technical limits 1. + 2.000 dynamic elements on the screen 2. + 3.000 watchers 3. real time apps, where data changes very often (★) depending on the device
  • 69. Some apps examples: stocks exchange google maps office apps OUTPUT: screen flickering, low UX, unresponsive screens And there's nothing you can do about it... except rewriting it in a lightweight framework
  • 70. 1. View watches / data bindings 2. What you see is what you show 3. The risk of polluting scopes 4. Core directives to avoid 5. Splitting the page 6. Miscellaneous 7. Limits
  • 71. Recap? (1) (1) be aware of too many data bindings (bindonce) (2) try to minimize the number of $digest cycles (3) have pre-computed values at template level (4) display only the visible elements (virtual scroll)
  • 72. Recap? (2) (5) be aware of core directives PERF problems (6) don't pollute your scopes and make them TDD friendly (7) watch out for external components (angular or non-angular) performance
  • 73. What's next? it's a good habit to think PERF (pre-$compile the code in your head) don't assume the frameworks are fast, whatever you may write watch out for memory leaks REMINDER: AngularJS is quite easy, just try it! ... and last but not least important: find a company that would allow you to grow your skills!
  • 74. Q / A