SlideShare a Scribd company logo
1 of 68
Download to read offline
HOW TO IMPROVE ANGULAR
2 PERFORMANCE?
Oleksandr Tryshchenko
Senior Front-end Developer, DataArt
tryshchenko.com
HOW TO IMPROVE ANGULAR
2 4 PERFORMANCE?
Oleksandr Tryshchenko
Senior Front-end Developer, DataArt
tryshchenko.com
128
What is 128 hours
• 3 working weeks and 1 day.
• 4 / 5 of your yearly vacation plan.
• Some money.
• Put your option here.
26 April 2017 6
Agenda
• Why does performance matter?
• Why do we need to tweak Angular 2?
• Problems we need to solve
• Solutions
• Conclusions
26 April 2017 7
What can we improve?
• Bundle size
• Application performance
26 April 2017 8
Infrastructure Improvements
26 April 2017 9
Bundle size: problem
26 April 2017 10
Not optimized FE 2752kb
Images Fonts HTML Scripts CSS
Bundle size: problem
26 April 2017 11
Optimized FE 822 kb
Images Fonts HTML Scripts CSS
Bundle size: problem
26 April 2017 12
0 50 100 150 200 250 300 350 400
2.5 Mb
1.5 Mb
0.5Mb
Loadingtime
56,6 kbit/s 1 Mbit/s 5 Mbit/s 50 Mbit/s
Ok. Why does it matter?
80% of internet users own a smartphone. (Smart Insights)
26 April 2017 13
…
Over 50% of smartphone users grab their smartphone
immediately after waking up. (ExpressPigeon, 2014)
26 April 2017 14
…
Google says 61% of users are unlikely to return to a mobile
site they had trouble accessing and 40% visit a competitor’s
site instead. (MicKinsey & Company)
26 April 2017 15
Ok. Why does it matter?
How can we reduce the bundle size?
• Compress pictures
• Minify styles, templates and scripts
• Remove useless code
26 April 2017 17
Handling images
• gulp-image-optimization
• gulp-image
• gulp-imagemin
• image-webpack-loader
…
26 April 2017 18
Handling styles
• A variety of Webpack loaders
• Angular CLI supports it by design
26 April 2017 19
Handling scripts
• A variety of Webpack loaders
• Angular CLI supports it by design
• … it is still huge. So we need to remove useless code.
26 April 2017 20
Tree Shaking
26 April 2017 21
0 500 1000 1500 2000 2500
Application 1
Application 2
Optimization Results
Before Tree Shaking,Kb With Tree Shaking,Kb
26 April 2017 22
🎄👋
26 April 2017
Tree Shaking
- Webpack marks useless code
- UglifyJsPlugin removes the code
How does tree shaking work?
26 April 2017 24
How does tree shaking work?
26 April 2017 25
How does tree shaking work?
26 April 2017 26
Tree Shaking
• For the moment Angular CLI has problems with tree
shaking.
• Use the latest version of Angular CLI.
• You need TypeScript 2 and WebPack 2.
26 April 2017 27
Compilation
26 April 2017 28
Compilation
• Just In Time Compilation (JIT)
• Ahead Of Time Compilation (AOT)
26 April 2017 29
What is JIT?
• Compiles in the browser.
• No need to build after changes.
• Default compiler in Angular 2 CLI.
26 April 2017 30
Why is AOT better?
• You don’t need to load compiler anymore.
• Faster loading.
• Better runtime performance.
• AOT is more secure, because JIT uses eval.
26 April 2017 31
AST (Abstract Syntax Tree)
26 April 2017 32
Script
Container
Members Decorators
Container
Members Decorators
Container
Members Decorators
AOT (Ahead Of Time Compilation)
26 April 2017 33
0 0.5 1 1.5 2 2.5 3
Bundle size, mb
AngularCLI defaultprojectsize
Compression,tree shaking and AOT
Compression with Tree Shaking
Raw
What can we improve?
• Bundle size
• Application performance
26 April 2017 35
Architecture Improvements
26 April 2017 36
Does architecture matter on
Frontend?
26 April 2017 37
What we can achieve with good
architecture?
• Better application performance
• Fewer API requests (app drives faster)
• Faster loading speed
26 April 2017 38
What architecture features are we
talking about?
• Make sure we’re using events efficiently.
• Make sure our data layer uses data efficiently.
• Control assets loading process.
• Organize correct components composition.
• Reduce DOM overhead.
26 April 2017 39
Problem: Army Of Listeners
26 April 2017 40
Solution: Change Detection
Strategies
• OnPush
• Default
26 April 2017 41
Change Detection Strategies
26 April 2017 43
Immutable ☺
26 April 2017 45
Mutable 🙁
26 April 2017 46
I wanna more!
26 April 2017 H T T P : / / W W W . J V A N D E M O . C O M / H O W - I - O P T I M I Z E D - M I N E S W E E P E R -
U S I N G - A N G U L A R - 2 - A N D - I M M U T A B L E - J S - T O - M A K E - I T - I N S A N E L Y - F A S T /
47
HOW I OPTIMIZED
MINESWEEPER USING
ANGULAR 2 AND
IMMUTABLE.JS TO
MAKE IT INSANELY
FAST
JURGEN VAN DE
MOERE
Immutable.js
26 April 2017 48
What to do with events?
• Use correct lifecycle hooks in the app.
• Be careful with your own events and use destructors.
• Avoid duplication of events.
• Avoid creation of useless events.
26 April 2017 49
What can we do with a data layer?
• Store static data in the browser. (Caching)
• Use pure RESTAPI (With HATEOAS)
• Use debouncing. Really.
• Background services.
26 April 2017 51
HATEAOS
26 April 2017 52
Why HATEOS?
• You don’t need to handle user roles on Front-End
anymore. At all.
• Server does it anyway during request/response cycle.
26 April 2017 53
26 April 2017
ReactiveX (Rx.js)
• One more way to organize the
asynchronous actions using JavaScript
• Leads to a new way of the components’
composition.
Problem: XHR Overhead
26 April 2017 55
Rx.js + A2
PROS
- Allows us to remove HTTP logic from the components.
- Absolutely simple
CONS
- Leads to a new way of the components’ composition.
- It isn’t a fastest solution.
26 April 2017 56
What Can We Do With Component’s
Composition?
26 April 2017 57
Components Composition
26 April 2017 58
Problem: Memory Leaks
26 April 2017 59
Solution: Zone.js, ngZones, Data
Composition
• Dying zone will remove the subscriptions for local
streams, but won’t do it to current ones in service, upper-
level components.
• Use ngOnDestroy lifecycle hook for removing such
subscriptions.
26 April 2017 60
Zone.js, ngZones, Data Composition
26 April 2017 H T T P S : / / G I T H U B . C O M / A N G U L A R / Z O N E . J S / 61
Problem: Binding Overhead
• A simple rule: don’t use two-way binding when you don’t
need it.
• ‘Singular’ binding isn’t shipped out of the box, but there
are several ways to implement it.
26 April 2017 62
One-directional «inside»:
26 April 2017 63
One-directional «outside»:
26 April 2017 64
Two-directional:
26 April 2017 65
Problem: DOM
• Don’t use DOM 🙁
26 April 2017 F O O T E R H E R E 66
What to with the DOM?
• Remove and add the elements back instead of hiding /
displaying.
• Don’t call DOM directly if it’s possible.
• When it isn’t possible use ElementRef,
@ViewChild/@ViewChildren.
26 April 2017 67
THANKS!
26 April 2017 68

More Related Content

What's hot

Angular - Angular is dead, long live the Angular
Angular - Angular is dead, long live the AngularAngular - Angular is dead, long live the Angular
Angular - Angular is dead, long live the AngularParis Polyzos
 
Wevquery: Testing Hypotheses about Web Interaction Patterns
Wevquery: Testing Hypotheses about Web Interaction PatternsWevquery: Testing Hypotheses about Web Interaction Patterns
Wevquery: Testing Hypotheses about Web Interaction PatternsMOVING Project
 
Modern .NET Apps - Codestock
Modern .NET Apps - CodestockModern .NET Apps - Codestock
Modern .NET Apps - CodestockSam Basu
 
LINEデリマでのElasticsearchの運用と監視の話
LINEデリマでのElasticsearchの運用と監視の話LINEデリマでのElasticsearchの運用と監視の話
LINEデリマでのElasticsearchの運用と監視の話LINE Corporation
 
Finding Cars and Hunting Down Logs - ElasticSearch @AutoScout24
Finding Cars and Hunting Down Logs - ElasticSearch @AutoScout24Finding Cars and Hunting Down Logs - ElasticSearch @AutoScout24
Finding Cars and Hunting Down Logs - ElasticSearch @AutoScout24Philipp Garbe
 
Lap around ASP.NET 5 - Dayton UG
Lap around ASP.NET 5 - Dayton UGLap around ASP.NET 5 - Dayton UG
Lap around ASP.NET 5 - Dayton UGSam Basu
 
This week in Neo4j - 7th October 2017
This week in Neo4j - 7th October 2017This week in Neo4j - 7th October 2017
This week in Neo4j - 7th October 2017Neo4j
 
Active record, standalone migrations, and working with Arel
Active record, standalone migrations, and working with ArelActive record, standalone migrations, and working with Arel
Active record, standalone migrations, and working with ArelAlex Tironati
 
Industrializing Machine learning pipelines
Industrializing Machine learning pipelinesIndustrializing Machine learning pipelines
Industrializing Machine learning pipelinesGermain Tanguy
 
Cnvrg webinar continual learning
Cnvrg webinar   continual learningCnvrg webinar   continual learning
Cnvrg webinar continual learningMaya Perry
 
Public and private cloud metadata and why it is useful
Public and private cloud metadata and why it is usefulPublic and private cloud metadata and why it is useful
Public and private cloud metadata and why it is usefulDevSecCon
 
.NET Core Foundations - Dependency Injection, Logging & Configuration - BASTA...
.NET Core Foundations - Dependency Injection, Logging & Configuration - BASTA....NET Core Foundations - Dependency Injection, Logging & Configuration - BASTA...
.NET Core Foundations - Dependency Injection, Logging & Configuration - BASTA...Christian Nagel
 
Bim softwares comparisons
Bim softwares comparisonsBim softwares comparisons
Bim softwares comparisonsNITISHNIWAS
 

What's hot (15)

Angular - Angular is dead, long live the Angular
Angular - Angular is dead, long live the AngularAngular - Angular is dead, long live the Angular
Angular - Angular is dead, long live the Angular
 
Wevquery: Testing Hypotheses about Web Interaction Patterns
Wevquery: Testing Hypotheses about Web Interaction PatternsWevquery: Testing Hypotheses about Web Interaction Patterns
Wevquery: Testing Hypotheses about Web Interaction Patterns
 
Modern .NET Apps - Codestock
Modern .NET Apps - CodestockModern .NET Apps - Codestock
Modern .NET Apps - Codestock
 
LINEデリマでのElasticsearchの運用と監視の話
LINEデリマでのElasticsearchの運用と監視の話LINEデリマでのElasticsearchの運用と監視の話
LINEデリマでのElasticsearchの運用と監視の話
 
Finding Cars and Hunting Down Logs - ElasticSearch @AutoScout24
Finding Cars and Hunting Down Logs - ElasticSearch @AutoScout24Finding Cars and Hunting Down Logs - ElasticSearch @AutoScout24
Finding Cars and Hunting Down Logs - ElasticSearch @AutoScout24
 
Async streams
Async streamsAsync streams
Async streams
 
Lap around ASP.NET 5 - Dayton UG
Lap around ASP.NET 5 - Dayton UGLap around ASP.NET 5 - Dayton UG
Lap around ASP.NET 5 - Dayton UG
 
This week in Neo4j - 7th October 2017
This week in Neo4j - 7th October 2017This week in Neo4j - 7th October 2017
This week in Neo4j - 7th October 2017
 
C# 8 and .NET Core 3
C# 8 and .NET Core 3C# 8 and .NET Core 3
C# 8 and .NET Core 3
 
Active record, standalone migrations, and working with Arel
Active record, standalone migrations, and working with ArelActive record, standalone migrations, and working with Arel
Active record, standalone migrations, and working with Arel
 
Industrializing Machine learning pipelines
Industrializing Machine learning pipelinesIndustrializing Machine learning pipelines
Industrializing Machine learning pipelines
 
Cnvrg webinar continual learning
Cnvrg webinar   continual learningCnvrg webinar   continual learning
Cnvrg webinar continual learning
 
Public and private cloud metadata and why it is useful
Public and private cloud metadata and why it is usefulPublic and private cloud metadata and why it is useful
Public and private cloud metadata and why it is useful
 
.NET Core Foundations - Dependency Injection, Logging & Configuration - BASTA...
.NET Core Foundations - Dependency Injection, Logging & Configuration - BASTA....NET Core Foundations - Dependency Injection, Logging & Configuration - BASTA...
.NET Core Foundations - Dependency Injection, Logging & Configuration - BASTA...
 
Bim softwares comparisons
Bim softwares comparisonsBim softwares comparisons
Bim softwares comparisons
 

Similar to How To Tweak Angular 2 Performance

Microprocessor Week 4-5 MCS-51 Arithmetic operation
Microprocessor Week 4-5 MCS-51 Arithmetic operationMicroprocessor Week 4-5 MCS-51 Arithmetic operation
Microprocessor Week 4-5 MCS-51 Arithmetic operationArkhom Jodtang
 
Readinggroup xiang 24112016
Readinggroup xiang 24112016Readinggroup xiang 24112016
Readinggroup xiang 24112016Xiang Zhang
 
MVC6 - NetConf UY 2017
MVC6 -  NetConf UY 2017MVC6 -  NetConf UY 2017
MVC6 - NetConf UY 2017David Revoledo
 
Growing in the Wild. The story by CUBRID Database Developers.
Growing in the Wild. The story by CUBRID Database Developers.Growing in the Wild. The story by CUBRID Database Developers.
Growing in the Wild. The story by CUBRID Database Developers.CUBRID
 
Scaling your CI Pipeline with Docker and Concourse
Scaling your CI Pipeline with Docker and ConcourseScaling your CI Pipeline with Docker and Concourse
Scaling your CI Pipeline with Docker and ConcourseChris Edwards, P.Eng.
 
Growing in the wild. The story by cubrid database developers (Esen Sagynov, E...
Growing in the wild. The story by cubrid database developers (Esen Sagynov, E...Growing in the wild. The story by cubrid database developers (Esen Sagynov, E...
Growing in the wild. The story by cubrid database developers (Esen Sagynov, E...Ontico
 
Implement DevOps Like a Unicorn—Even If You’re Not One
Implement DevOps Like a Unicorn—Even If You’re Not OneImplement DevOps Like a Unicorn—Even If You’re Not One
Implement DevOps Like a Unicorn—Even If You’re Not OneTechWell
 
Test Data Preparation: Tips and Tricks
Test Data Preparation: Tips and TricksTest Data Preparation: Tips and Tricks
Test Data Preparation: Tips and TricksSQALab
 
Refactoring, Therapeutic Attitude to Programming.
Refactoring, Therapeutic Attitude to Programming.Refactoring, Therapeutic Attitude to Programming.
Refactoring, Therapeutic Attitude to Programming.Amin Shahnazari
 
containerdays2017 - Microservice and now?
containerdays2017 - Microservice and now?containerdays2017 - Microservice and now?
containerdays2017 - Microservice and now?Björn Jessen-Noak
 
Anyone Can Build a Site, Even You! Create a Microsite with Oracle Sites Cloud...
Anyone Can Build a Site, Even You! Create a Microsite with Oracle Sites Cloud...Anyone Can Build a Site, Even You! Create a Microsite with Oracle Sites Cloud...
Anyone Can Build a Site, Even You! Create a Microsite with Oracle Sites Cloud...Revelation Technologies
 
Room 2 - 5 - Seong Soo - NHN Cloud - Upstream contribution mentoring program ...
Room 2 - 5 - Seong Soo - NHN Cloud - Upstream contribution mentoring program ...Room 2 - 5 - Seong Soo - NHN Cloud - Upstream contribution mentoring program ...
Room 2 - 5 - Seong Soo - NHN Cloud - Upstream contribution mentoring program ...Vietnam Open Infrastructure User Group
 
Why are we excited about MySQL 8? / Петр Зайцев (Percona)
Why are we excited about MySQL 8? / Петр Зайцев (Percona)Why are we excited about MySQL 8? / Петр Зайцев (Percona)
Why are we excited about MySQL 8? / Петр Зайцев (Percona)Ontico
 
Energy Saving Trust - Esri UK Annual Conference 2016
Energy Saving Trust - Esri UK Annual Conference 2016Energy Saving Trust - Esri UK Annual Conference 2016
Energy Saving Trust - Esri UK Annual Conference 2016Esri UK
 
Oracle EBS database upgrade to 12c
Oracle EBS database upgrade to 12cOracle EBS database upgrade to 12c
Oracle EBS database upgrade to 12cvasuballa
 
Webinar slides: DevOps Tutorial: how to automate your database infrastructure
Webinar slides: DevOps Tutorial: how to automate your database infrastructureWebinar slides: DevOps Tutorial: how to automate your database infrastructure
Webinar slides: DevOps Tutorial: how to automate your database infrastructureSeveralnines
 
Data Day Texas 2017: Scaling Data Science at Stitch Fix
Data Day Texas 2017: Scaling Data Science at Stitch FixData Day Texas 2017: Scaling Data Science at Stitch Fix
Data Day Texas 2017: Scaling Data Science at Stitch FixStefan Krawczyk
 
Best Practices - By Lofi Dewanto
Best Practices - By Lofi DewantoBest Practices - By Lofi Dewanto
Best Practices - By Lofi DewantoGWTcon
 
Optimization Problems Solved by Different Platforms Say Optimum Tool Box (Mat...
Optimization Problems Solved by Different Platforms Say Optimum Tool Box (Mat...Optimization Problems Solved by Different Platforms Say Optimum Tool Box (Mat...
Optimization Problems Solved by Different Platforms Say Optimum Tool Box (Mat...IRJET Journal
 

Similar to How To Tweak Angular 2 Performance (20)

Microprocessor Week 4-5 MCS-51 Arithmetic operation
Microprocessor Week 4-5 MCS-51 Arithmetic operationMicroprocessor Week 4-5 MCS-51 Arithmetic operation
Microprocessor Week 4-5 MCS-51 Arithmetic operation
 
Readinggroup xiang 24112016
Readinggroup xiang 24112016Readinggroup xiang 24112016
Readinggroup xiang 24112016
 
MVC6 - NetConf UY 2017
MVC6 -  NetConf UY 2017MVC6 -  NetConf UY 2017
MVC6 - NetConf UY 2017
 
Growing in the Wild. The story by CUBRID Database Developers.
Growing in the Wild. The story by CUBRID Database Developers.Growing in the Wild. The story by CUBRID Database Developers.
Growing in the Wild. The story by CUBRID Database Developers.
 
[TestWarez 2017] Automated Testing for Common Errors and Difference Recogniti...
[TestWarez 2017] Automated Testing for Common Errors and Difference Recogniti...[TestWarez 2017] Automated Testing for Common Errors and Difference Recogniti...
[TestWarez 2017] Automated Testing for Common Errors and Difference Recogniti...
 
Scaling your CI Pipeline with Docker and Concourse
Scaling your CI Pipeline with Docker and ConcourseScaling your CI Pipeline with Docker and Concourse
Scaling your CI Pipeline with Docker and Concourse
 
Growing in the wild. The story by cubrid database developers (Esen Sagynov, E...
Growing in the wild. The story by cubrid database developers (Esen Sagynov, E...Growing in the wild. The story by cubrid database developers (Esen Sagynov, E...
Growing in the wild. The story by cubrid database developers (Esen Sagynov, E...
 
Implement DevOps Like a Unicorn—Even If You’re Not One
Implement DevOps Like a Unicorn—Even If You’re Not OneImplement DevOps Like a Unicorn—Even If You’re Not One
Implement DevOps Like a Unicorn—Even If You’re Not One
 
Test Data Preparation: Tips and Tricks
Test Data Preparation: Tips and TricksTest Data Preparation: Tips and Tricks
Test Data Preparation: Tips and Tricks
 
Refactoring, Therapeutic Attitude to Programming.
Refactoring, Therapeutic Attitude to Programming.Refactoring, Therapeutic Attitude to Programming.
Refactoring, Therapeutic Attitude to Programming.
 
containerdays2017 - Microservice and now?
containerdays2017 - Microservice and now?containerdays2017 - Microservice and now?
containerdays2017 - Microservice and now?
 
Anyone Can Build a Site, Even You! Create a Microsite with Oracle Sites Cloud...
Anyone Can Build a Site, Even You! Create a Microsite with Oracle Sites Cloud...Anyone Can Build a Site, Even You! Create a Microsite with Oracle Sites Cloud...
Anyone Can Build a Site, Even You! Create a Microsite with Oracle Sites Cloud...
 
Room 2 - 5 - Seong Soo - NHN Cloud - Upstream contribution mentoring program ...
Room 2 - 5 - Seong Soo - NHN Cloud - Upstream contribution mentoring program ...Room 2 - 5 - Seong Soo - NHN Cloud - Upstream contribution mentoring program ...
Room 2 - 5 - Seong Soo - NHN Cloud - Upstream contribution mentoring program ...
 
Why are we excited about MySQL 8? / Петр Зайцев (Percona)
Why are we excited about MySQL 8? / Петр Зайцев (Percona)Why are we excited about MySQL 8? / Петр Зайцев (Percona)
Why are we excited about MySQL 8? / Петр Зайцев (Percona)
 
Energy Saving Trust - Esri UK Annual Conference 2016
Energy Saving Trust - Esri UK Annual Conference 2016Energy Saving Trust - Esri UK Annual Conference 2016
Energy Saving Trust - Esri UK Annual Conference 2016
 
Oracle EBS database upgrade to 12c
Oracle EBS database upgrade to 12cOracle EBS database upgrade to 12c
Oracle EBS database upgrade to 12c
 
Webinar slides: DevOps Tutorial: how to automate your database infrastructure
Webinar slides: DevOps Tutorial: how to automate your database infrastructureWebinar slides: DevOps Tutorial: how to automate your database infrastructure
Webinar slides: DevOps Tutorial: how to automate your database infrastructure
 
Data Day Texas 2017: Scaling Data Science at Stitch Fix
Data Day Texas 2017: Scaling Data Science at Stitch FixData Day Texas 2017: Scaling Data Science at Stitch Fix
Data Day Texas 2017: Scaling Data Science at Stitch Fix
 
Best Practices - By Lofi Dewanto
Best Practices - By Lofi DewantoBest Practices - By Lofi Dewanto
Best Practices - By Lofi Dewanto
 
Optimization Problems Solved by Different Platforms Say Optimum Tool Box (Mat...
Optimization Problems Solved by Different Platforms Say Optimum Tool Box (Mat...Optimization Problems Solved by Different Platforms Say Optimum Tool Box (Mat...
Optimization Problems Solved by Different Platforms Say Optimum Tool Box (Mat...
 

More from Oleksandr Tryshchenko

More from Oleksandr Tryshchenko (8)

PWA to React Native migration
PWA to React Native migrationPWA to React Native migration
PWA to React Native migration
 
Web Scraping
Web ScrapingWeb Scraping
Web Scraping
 
2018 grai
2018 grai2018 grai
2018 grai
 
Mobile Applications with Angular 4 and Ionic 3
Mobile Applications with Angular 4 and Ionic 3Mobile Applications with Angular 4 and Ionic 3
Mobile Applications with Angular 4 and Ionic 3
 
20 000 Leagues Under The Angular 4
20 000 Leagues Under The Angular 420 000 Leagues Under The Angular 4
20 000 Leagues Under The Angular 4
 
ES6 Generators On Koa.js Example
ES6 Generators On Koa.js ExampleES6 Generators On Koa.js Example
ES6 Generators On Koa.js Example
 
Angular 2 On Production
Angular 2 On ProductionAngular 2 On Production
Angular 2 On Production
 
ES6 basics
ES6 basicsES6 basics
ES6 basics
 

Recently uploaded

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 

Recently uploaded (20)

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 

How To Tweak Angular 2 Performance

  • 1.
  • 2.
  • 3. HOW TO IMPROVE ANGULAR 2 PERFORMANCE? Oleksandr Tryshchenko Senior Front-end Developer, DataArt tryshchenko.com
  • 4. HOW TO IMPROVE ANGULAR 2 4 PERFORMANCE? Oleksandr Tryshchenko Senior Front-end Developer, DataArt tryshchenko.com
  • 5. 128
  • 6. What is 128 hours • 3 working weeks and 1 day. • 4 / 5 of your yearly vacation plan. • Some money. • Put your option here. 26 April 2017 6
  • 7. Agenda • Why does performance matter? • Why do we need to tweak Angular 2? • Problems we need to solve • Solutions • Conclusions 26 April 2017 7
  • 8. What can we improve? • Bundle size • Application performance 26 April 2017 8
  • 10. Bundle size: problem 26 April 2017 10 Not optimized FE 2752kb Images Fonts HTML Scripts CSS
  • 11. Bundle size: problem 26 April 2017 11 Optimized FE 822 kb Images Fonts HTML Scripts CSS
  • 12. Bundle size: problem 26 April 2017 12 0 50 100 150 200 250 300 350 400 2.5 Mb 1.5 Mb 0.5Mb Loadingtime 56,6 kbit/s 1 Mbit/s 5 Mbit/s 50 Mbit/s
  • 13. Ok. Why does it matter? 80% of internet users own a smartphone. (Smart Insights) 26 April 2017 13
  • 14. … Over 50% of smartphone users grab their smartphone immediately after waking up. (ExpressPigeon, 2014) 26 April 2017 14
  • 15. … Google says 61% of users are unlikely to return to a mobile site they had trouble accessing and 40% visit a competitor’s site instead. (MicKinsey & Company) 26 April 2017 15
  • 16. Ok. Why does it matter?
  • 17. How can we reduce the bundle size? • Compress pictures • Minify styles, templates and scripts • Remove useless code 26 April 2017 17
  • 18. Handling images • gulp-image-optimization • gulp-image • gulp-imagemin • image-webpack-loader … 26 April 2017 18
  • 19. Handling styles • A variety of Webpack loaders • Angular CLI supports it by design 26 April 2017 19
  • 20. Handling scripts • A variety of Webpack loaders • Angular CLI supports it by design • … it is still huge. So we need to remove useless code. 26 April 2017 20
  • 21. Tree Shaking 26 April 2017 21 0 500 1000 1500 2000 2500 Application 1 Application 2 Optimization Results Before Tree Shaking,Kb With Tree Shaking,Kb
  • 22. 26 April 2017 22 🎄👋
  • 23. 26 April 2017 Tree Shaking - Webpack marks useless code - UglifyJsPlugin removes the code
  • 24. How does tree shaking work? 26 April 2017 24
  • 25. How does tree shaking work? 26 April 2017 25
  • 26. How does tree shaking work? 26 April 2017 26
  • 27. Tree Shaking • For the moment Angular CLI has problems with tree shaking. • Use the latest version of Angular CLI. • You need TypeScript 2 and WebPack 2. 26 April 2017 27
  • 29. Compilation • Just In Time Compilation (JIT) • Ahead Of Time Compilation (AOT) 26 April 2017 29
  • 30. What is JIT? • Compiles in the browser. • No need to build after changes. • Default compiler in Angular 2 CLI. 26 April 2017 30
  • 31. Why is AOT better? • You don’t need to load compiler anymore. • Faster loading. • Better runtime performance. • AOT is more secure, because JIT uses eval. 26 April 2017 31
  • 32. AST (Abstract Syntax Tree) 26 April 2017 32 Script Container Members Decorators Container Members Decorators Container Members Decorators
  • 33. AOT (Ahead Of Time Compilation) 26 April 2017 33 0 0.5 1 1.5 2 2.5 3 Bundle size, mb AngularCLI defaultprojectsize Compression,tree shaking and AOT Compression with Tree Shaking Raw
  • 34.
  • 35. What can we improve? • Bundle size • Application performance 26 April 2017 35
  • 37. Does architecture matter on Frontend? 26 April 2017 37
  • 38. What we can achieve with good architecture? • Better application performance • Fewer API requests (app drives faster) • Faster loading speed 26 April 2017 38
  • 39. What architecture features are we talking about? • Make sure we’re using events efficiently. • Make sure our data layer uses data efficiently. • Control assets loading process. • Organize correct components composition. • Reduce DOM overhead. 26 April 2017 39
  • 40. Problem: Army Of Listeners 26 April 2017 40
  • 41. Solution: Change Detection Strategies • OnPush • Default 26 April 2017 41
  • 42.
  • 44.
  • 47. I wanna more! 26 April 2017 H T T P : / / W W W . J V A N D E M O . C O M / H O W - I - O P T I M I Z E D - M I N E S W E E P E R - U S I N G - A N G U L A R - 2 - A N D - I M M U T A B L E - J S - T O - M A K E - I T - I N S A N E L Y - F A S T / 47 HOW I OPTIMIZED MINESWEEPER USING ANGULAR 2 AND IMMUTABLE.JS TO MAKE IT INSANELY FAST JURGEN VAN DE MOERE
  • 49. What to do with events? • Use correct lifecycle hooks in the app. • Be careful with your own events and use destructors. • Avoid duplication of events. • Avoid creation of useless events. 26 April 2017 49
  • 50.
  • 51. What can we do with a data layer? • Store static data in the browser. (Caching) • Use pure RESTAPI (With HATEOAS) • Use debouncing. Really. • Background services. 26 April 2017 51
  • 53. Why HATEOS? • You don’t need to handle user roles on Front-End anymore. At all. • Server does it anyway during request/response cycle. 26 April 2017 53
  • 54. 26 April 2017 ReactiveX (Rx.js) • One more way to organize the asynchronous actions using JavaScript • Leads to a new way of the components’ composition.
  • 55. Problem: XHR Overhead 26 April 2017 55
  • 56. Rx.js + A2 PROS - Allows us to remove HTTP logic from the components. - Absolutely simple CONS - Leads to a new way of the components’ composition. - It isn’t a fastest solution. 26 April 2017 56
  • 57. What Can We Do With Component’s Composition? 26 April 2017 57
  • 59. Problem: Memory Leaks 26 April 2017 59
  • 60. Solution: Zone.js, ngZones, Data Composition • Dying zone will remove the subscriptions for local streams, but won’t do it to current ones in service, upper- level components. • Use ngOnDestroy lifecycle hook for removing such subscriptions. 26 April 2017 60
  • 61. Zone.js, ngZones, Data Composition 26 April 2017 H T T P S : / / G I T H U B . C O M / A N G U L A R / Z O N E . J S / 61
  • 62. Problem: Binding Overhead • A simple rule: don’t use two-way binding when you don’t need it. • ‘Singular’ binding isn’t shipped out of the box, but there are several ways to implement it. 26 April 2017 62
  • 66. Problem: DOM • Don’t use DOM 🙁 26 April 2017 F O O T E R H E R E 66
  • 67. What to with the DOM? • Remove and add the elements back instead of hiding / displaying. • Don’t call DOM directly if it’s possible. • When it isn’t possible use ElementRef, @ViewChild/@ViewChildren. 26 April 2017 67