Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Angular Performance 101
Search
Aviv Ben-Yosef
June 17, 2014
Programming
1
18k
Angular Performance 101
From JS-IL 2014, given on June 17, 2014.
Aviv Ben-Yosef
June 17, 2014
Tweet
Share
More Decks by Aviv Ben-Yosef
See All by Aviv Ben-Yosef
HTTP API Design: UX for the Nitpickeriest
avivby
0
54
Stuff You Didn't Know You Can Do with RSpec
avivby
1
3.1k
Introduction to Rubinius
avivby
1
4k
DRY Introduction
avivby
1
290
How BillGuard Does MongoDB
avivby
5
3.2k
Other Decks in Programming
See All in Programming
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
140
gunshi
kazupon
1
140
大規模Cloud Native環境におけるFalcoの運用
owlinux1000
0
260
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
920
AI Agent Dojo #4: watsonx Orchestrate ADK体験
oniak3ibm
PRO
0
130
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
130
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
5.7k
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.6k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
160
AtCoder Conference 2025「LLM時代のAHC」
imjk
2
700
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
3.9k
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
220
Featured
See All Featured
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
270
4 Signs Your Business is Dying
shpigford
187
22k
The Cost Of JavaScript in 2023
addyosmani
55
9.4k
WENDY [Excerpt]
tessaabrams
9
35k
Documentation Writing (for coders)
carmenintech
77
5.2k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
116
100k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
1
42
Information Architects: The Missing Link in Design Systems
soysaucechin
0
750
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
430
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
85
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.6k
Transcript
Angular Performance 101
Disclaimer
“Premature optimization is the root of all Evil”
A story
None
<div ng-repeat=“task in tasks”> <span> {{ task.title }} </span> <span>
{{ task.date | fromNow }} </span> </div>
Why did it keep updating?
None
$interval(function() { $http.get(‘/events’) .success(function(events) { if (events) { $scope.events =
events; } }); }, 20 * 1000);
Why?
Angular == SO. MUCH. MAGIC.
“With great power comes great responsibility”
We’ll learn How dirty checking is performed When it runs
What you should do
The Secret
Magic == Dirty checking
How dirty checking is performed
Digest Loop
Digest == Run all watch expressions
$scope.$watch()
… and {{ stuff }}
… and ng-show=“foo()”
… and isolated scope variables scope: {foo: ‘=’}
… and {{ value | myFilter }}
… and ng-repeat itself
Watch Expressions $scope.$watch() {{ stuff }} ng-show=“list.length > 0” isolated
scope bindings: {foo: ‘=’} filters: {{ date | fromNow }} ng-repeat Basically everything
When does it run?
User actions
ng-click
ng-change
ng-model
… and $http responses
… and when $q promises are resolved
… and when using $timeout or $interval
… and whenever you call $scope.$apply() or $scope.$digest()
When digest runs User actions (ng-click, ng-model, etc.) $http responses
$q promises resolved $timeout / $interval $scope.$apply() / $scope.$digest() Basically: a lot of things
So? Who cares?
None
But when the shit hits the fan
You click and the screen freezes for a while The
only* performance issue that is angular’s fault
Are all clicks slow? Or just a certain screen?
One Screen is Slow That screen has bad scopes: Too
many watches Watch handlers that take too long
Everything is Slow Your digest loop is taking too long
You’re doing it wrong
Pinpoint it
Batarang
See watch expression
See slow expressions
Time Your $digest console.time(‘digest’); $rootScope.$digest(); console.timeEnd(‘digest’); http://jsfiddle.net/mbRf8/
What you should do
Make watches faster
Making Watches Faster Switch deep watch with $watchCollection $scope.$watch(‘myList’, function()
{}, true); ! $scope.$watchCollection(‘myList’, function() {});
Making Watches Faster Deep watch a subset $scope.$watch(‘myList’, function() {},
true); ! $scope.$watch( function() {return _.pluck($scope.myList, ‘id’);}, function() {}, true);
Making Watches Faster Make the change handler more performant
Have less watches
ng-repeat is your enemy
ng-repeat is your enemy Use track by <div ng-repeat=“task in
tasks track by task.id”> http://bit.ly/1kyvet7
ng-repeat is your enemy Paginate <div ng-repeat=“task in tasks”> !
<div ng-repeat=“task in tasksPage”>
ng-repeat is your enemy Row Virtualization à-la ng-grid http://angular-ui.github.io/ng-grid/
ng-repeat is your enemy Bind Once https://github.com/Pasvaz/bindonce <div bindonce ng-repeat=“task
in tasks”> ! <span bo-text=“task.title”></span> ! </div>
Have Less Watches ng-hide & ng-show elements are still there,
consider using ng-if Consider replacing filters with pre-calculated values
Badass AKA “I’m Desperate”
Badass Mode Write an angular-less widget
Your Mission Pinpoint bad watches Make watches faster Use less
watches
Thank You! Aviv Ben-Yosef @avivby www.deflect.io ! My angular &
web development newsletter www.codelord.net