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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Aviv Ben-Yosef
June 17, 2014
Programming
18k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Angular Performance 101
From JS-IL 2014, given on June 17, 2014.
Aviv Ben-Yosef
June 17, 2014
More Decks by Aviv Ben-Yosef
See All by Aviv Ben-Yosef
HTTP API Design: UX for the Nitpickeriest
avivby
0
59
Stuff You Didn't Know You Can Do with RSpec
avivby
1
3.2k
Introduction to Rubinius
avivby
1
4k
DRY Introduction
avivby
1
300
How BillGuard Does MongoDB
avivby
5
3.2k
Other Decks in Programming
See All in Programming
【デモ】Kiroで体験する仕様駆動開発|設計からコーディングまでAIと進める開発フロー
cmkudo
0
580
Discordを用いたラボオートメーション関連情報収集の自動化
noguhiro2002
0
500
高専キャリア LT 発表内容
crysta1221
6
5.5k
AI駆動開発にグラフDBを重ねてみた
satoshi256kbyte
2
740
DroidKaigi 2026 「個人開発という実験場: Android エンジニアが手にする4つの自由」
slashnephy
0
220
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
470
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
3
1k
Laravelのアプリケーションをどこにデプロイするか #ツナギメオフライン.9
akase244
0
120
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
110
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
680
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
6
2.3k
思考垂れ流し開発 ~音声入力 × AIエージェント × 開発ハーネスによる試行錯誤~
npostring
0
860
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
450
The Spectacular Lies of Maps
axbom
PRO
1
980
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
310
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
250
The SEO Collaboration Effect
kristinabergwall1
1
550
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Ruling the World: When Life Gets Gamed
codingconduct
0
320
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
320
First, design no harm
axbom
PRO
2
1.3k
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