SlideShare a Scribd company logo
1 of 53
V I R T U A L C O N F E R E N C E / / N O V - D E C 2 0 2 0 / / P R E S E N T E D B Y E P A M
V I R T U A L C O N F E R E N C E / / N O V - D E C 2 0 2 0 / / P R E S E N T E D B Y E P A M
Writing Performant
Front-end Code
LY U B O M I R B O Z H I N O V
ADAPT BY ZED
Who Am I?
Lyu b omir
B ozh in ov
Lead Software Engineer
Lead Software Engineer @ EPAM. Author. Speaker.
But most importantly, a tinkerer at heart, who
believes one should always leave the code better
than they found it - and apply the same to
everything.
3
About Me
4
About Me
So, yeah, I write code for a living.
5
About Me
Sometimes I even know why it works!
ADAPT BY ZED
• MAKE IT WORK
• MAKE IT FAST
• MAKE IT PRETTY
6
Intro
ADAPT BY ZED
• MAKE IT WORK
• MAKE IT FAST
• MAKE IT PRETTY
HOW OFTEN DO YOU IGNORE CODE PERFORMANCE?
7
Intro
Level Zero: Code Performance
The Art of the Tinkerer
1
ADAPT BY ZED
9
Computational Complexity: Time v Space
Sometimes the best way to visualise something is with
a poor drawing of random ‘wibbly-wobbly’ lines.
ADAPT BY ZED
10
Computational Complexity: The Problem
In the classic find all anagrams in a dataset problem,
you could iterate every time. Or just pre-process and use KVPs.
v
ADAPT BY ZED
11
Computational Complexity: Time v Space
Hungry, hungry Chrome tabs!
ADAPT BY ZED
12
Computational Complexity: Time v Space
CompSci101 Reference
13
Premature Optimisation
What do I mean by that?
Basically any situation where one
tries to make the code run faster
before even having completed the
functionality.
14
Level Zero Fast?
Speed can be weird at this level.
15
Measure!
Measure your code speed!
And do it with enough consistency
across the codebase to have an
early-warning system for
performance problems.
16
Measure How?
USER TIMING API
MARKS & MEASURES
https://developer.mozilla.org/en-
US/docs/Web/API/User_Timing_API
ADAPT BY ZED
https://caniuse.com/#search=user-timing
17
Measure How?
ADAPT BY ZEDLevel Zero: How & Why?
18
WHY
MEASURE
LOG
TINKER
RINSE
REPEAT
SLOW CODE IS BAD
HOW
Level One: Rendering
Performance
Precision is the Key
2
ADAPT BY ZED
Our favourite language in the multiverse is single-threaded. 
20
The Event Loop
ADAPT BY ZED
The Pixel Pipeline. Source: web.dev
21
The Pixel Pipeline
Say ‘hello’ to your new best friend!
22
The Performance Tab
23
Optimise Your JS
Your code drives the entire pipeline!
ADAPT BY ZED
Changing an element’s width or class will trigger visual
changes. ‘It’s only logical.’
24
Optimise Your JS
ADAPT BY ZED
Anything small that will trigger a visual update should be done
in a RAF call to ensure it’s finished on time. No setTimeout!
25
Optimise Your JS
ADAPT BY ZED
Split the work into smaller tasks, push them onto a stack, and
then use RAF calls to deal with them one by one.
26
Optimise Your JS
ADAPT BY ZED
Just spin up a web worker to keep the main thread free of the
long-running computation.
27
Optimise Your JS
ADAPT BY ZED
The possibilities are endless.
28
Optimise Your JS
ADAPT BY ZED
Jason Miller (@developit)
29
Optimise Your JS
greenlet: https://www.npmjs.com/package/greenlet
workerize: https://www.npmjs.com/package/workerize-loader
30
Improve Style Calculations
We all joke around that CSS is a necessary evil, but the reality
is that we simply MUST try to keep it in check.
31
Improve Style Calculations
SMACSS: http://smacss.com/
BEM: http://getbem.com/introduction/
https://www.smashingmagazine.com/20
13/10/challenging-css-best-practices-
atomic-approach/
32
Minimise Layout Complexity
The fewer elements you have in your DOM tree, the
more quickly the browser will calculate the locations and
dimensions of all of them.
33
Paint and Compositing
• All property changes except transform and
opacity will trigger a repaint.
• Identify excessive paints with the dev tools
and create a separate layer.
• But too many layers at the compositing
stage can have a performance impact.
ADAPT BY ZED
The four parts of the RAIL model are basically four
perspectives on a web app’s state. Picture source: web.dev
34
The RAIL Model
ADAPT BY ZEDThe RAIL Model
35
10ms50ms
ADAPT BY ZED
Source: web.dev
36
The RAIL Model
ADAPT BY ZEDLevel One: How & Why?
37
WHY
THE PERFORMANCE TAB
OPTIMISE JAVASCRIPT EXECUTION
IMPROVE STYLE CALCULATIONS
MINIMISE LAYOUT COMPLEXITY
SIMPLIFY PAINT AND MANAGE LAYERS
KEEP THE RAIL MODEL IN MIND
VISUAL JANK AND STUTTER IS JUST BAD
UX
SLOW RENDERING WILL MAKE THE
USER FRUSTRATED
HOW
Level Two: Framework and
Bundle
Optimise Everything!
3
ADAPT BY ZED
There are number of other auto-magical features in modern
frameworks – usually just a boolean flag in a JSON file.
39
The Pros and Cons of Frameworks
ADAPT BY ZED
I’ve had the misfortune to write jQuery in IE6. It was about as
fun as it sounds.
40
The Pros and Cons of Frameworks
ADAPT BY ZED
Bundle analyzer: https://www.npmjs.com/package/webpack-
bundle-analyzer
41
The Pros and Cons of Frameworks
ADAPT BY ZED
Redux + React
42
The Pros and Cons of Frameworks
ADAPT BY ZED
Preact + Unistore
https://preactjs.com/
https://www.npmjs.com/package/unistore
43
The Pros and Cons of Frameworks
ADAPT BY ZED
Intro to PWAs: https://web.dev/progressive-web-apps
44
Going PWA
Lighthouse CI:
https://github.com/GoogleChrome/l
ighthouse-ci
45
Shed Some Light
ADAPT BY ZEDLevel Two: How & Why?
46
WHY
‘RIGHT TOOL FOR THE JOB’ TO ACHIEVE A GREAT USER EXPERIENCE
HOW
Level Three: The Network
Waterfall
Every Byte Matters
4
ADAPT BY ZED
It requires an absurd amount of tinkering to get it right. And
the solution is different for every project.
48
The Network Waterfall
ADAPT BY ZED
Addy Osmani (@addyosmani)
49
Optimise Your JS
critical: https://github.com/addyosmani/critical
ADAPT BY ZEDLevel Three: How & Why?
50
WHY
SOMEWHAT CLEAR CRYSTAL CLEAR
HOW
ADAPT BY ZED
None of the things I’ve mentioned here today are FINAL.
51
Final Words
52
Final Words
Largest Contentful Paint (LCP)
First Input Delay (FID)
Cumulative Layout Shift (CLS)
Total Blocking Time (TBT)
Keep an eye on https://web.dev
V I R T U A L C O N F E R E N C E / / N O V - D E C 2 0 2 0 / / P R E S E N T E D B Y E P A M
Thank you!
LinkedIn: https://www.linkedin.com/in/lyubomir-bozhinov/
Twitter: https://twitter.com/TheElegantDev

More Related Content

What's hot

Joel Arvidsson, Klarna. What You See is What You Get – a case for visual testing
Joel Arvidsson, Klarna. What You See is What You Get – a case for visual testingJoel Arvidsson, Klarna. What You See is What You Get – a case for visual testing
Joel Arvidsson, Klarna. What You See is What You Get – a case for visual testingIT Arena
 
Testing Storm components with Groovy and Spock
Testing Storm components with Groovy and SpockTesting Storm components with Groovy and Spock
Testing Storm components with Groovy and SpockEugene Dvorkin
 
Groovy - Why and Where?
Groovy  - Why and Where?Groovy  - Why and Where?
Groovy - Why and Where?Naresha K
 
[D2대학생세미나] frontend개발자가 들려주는 개발 이야기
[D2대학생세미나] frontend개발자가 들려주는 개발 이야기[D2대학생세미나] frontend개발자가 들려주는 개발 이야기
[D2대학생세미나] frontend개발자가 들려주는 개발 이야기NAVER D2
 
Discovery Education streaming and Google Earth
Discovery Education streaming and Google EarthDiscovery Education streaming and Google Earth
Discovery Education streaming and Google EarthMike Bryant
 
Ops is dead. long live ops.
Ops is dead. long live ops.Ops is dead. long live ops.
Ops is dead. long live ops.Outlyer
 
Large Scale Crash Dump Analysis with SuperDump
Large Scale Crash Dump Analysis with SuperDumpLarge Scale Crash Dump Analysis with SuperDump
Large Scale Crash Dump Analysis with SuperDumpChristoph Neumüller
 
息子たちがローマ字勉強するための <s>HTML5</s> Web標準 アプリ作ってみた
息子たちがローマ字勉強するための <s>HTML5</s> Web標準 アプリ作ってみた息子たちがローマ字勉強するための <s>HTML5</s> Web標準 アプリ作ってみた
息子たちがローマ字勉強するための <s>HTML5</s> Web標準 アプリ作ってみたJun-ichi Sakamoto
 
那些年,我們一起玩的萬花筒(Kaliedoscopic)
那些年,我們一起玩的萬花筒(Kaliedoscopic)那些年,我們一起玩的萬花筒(Kaliedoscopic)
那些年,我們一起玩的萬花筒(Kaliedoscopic)PRADA Hsiung
 
html5 & phonegap
html5 & phonegaphtml5 & phonegap
html5 & phonegapCaesar Chi
 
Follow these reasons to know java’s importance
Follow these reasons to know java’s importanceFollow these reasons to know java’s importance
Follow these reasons to know java’s importancenishajj
 
YeurDreamin' - Put the Wow! into your Flow with Lightning Experience
YeurDreamin'  - Put the Wow! into your Flow with Lightning ExperienceYeurDreamin'  - Put the Wow! into your Flow with Lightning Experience
YeurDreamin' - Put the Wow! into your Flow with Lightning ExperienceDaniel Stange
 

What's hot (16)

Coffee script throwdown
Coffee script throwdownCoffee script throwdown
Coffee script throwdown
 
Deployment talk dpc 13
Deployment talk dpc 13Deployment talk dpc 13
Deployment talk dpc 13
 
Joel Arvidsson, Klarna. What You See is What You Get – a case for visual testing
Joel Arvidsson, Klarna. What You See is What You Get – a case for visual testingJoel Arvidsson, Klarna. What You See is What You Get – a case for visual testing
Joel Arvidsson, Klarna. What You See is What You Get – a case for visual testing
 
Testing Storm components with Groovy and Spock
Testing Storm components with Groovy and SpockTesting Storm components with Groovy and Spock
Testing Storm components with Groovy and Spock
 
Groovy - Why and Where?
Groovy  - Why and Where?Groovy  - Why and Where?
Groovy - Why and Where?
 
[D2대학생세미나] frontend개발자가 들려주는 개발 이야기
[D2대학생세미나] frontend개발자가 들려주는 개발 이야기[D2대학생세미나] frontend개발자가 들려주는 개발 이야기
[D2대학생세미나] frontend개발자가 들려주는 개발 이야기
 
Discovery Education streaming and Google Earth
Discovery Education streaming and Google EarthDiscovery Education streaming and Google Earth
Discovery Education streaming and Google Earth
 
Ops is dead. long live ops.
Ops is dead. long live ops.Ops is dead. long live ops.
Ops is dead. long live ops.
 
Large Scale Crash Dump Analysis with SuperDump
Large Scale Crash Dump Analysis with SuperDumpLarge Scale Crash Dump Analysis with SuperDump
Large Scale Crash Dump Analysis with SuperDump
 
息子たちがローマ字勉強するための <s>HTML5</s> Web標準 アプリ作ってみた
息子たちがローマ字勉強するための <s>HTML5</s> Web標準 アプリ作ってみた息子たちがローマ字勉強するための <s>HTML5</s> Web標準 アプリ作ってみた
息子たちがローマ字勉強するための <s>HTML5</s> Web標準 アプリ作ってみた
 
那些年,我們一起玩的萬花筒(Kaliedoscopic)
那些年,我們一起玩的萬花筒(Kaliedoscopic)那些年,我們一起玩的萬花筒(Kaliedoscopic)
那些年,我們一起玩的萬花筒(Kaliedoscopic)
 
html5 & phonegap
html5 & phonegaphtml5 & phonegap
html5 & phonegap
 
Follow these reasons to know java’s importance
Follow these reasons to know java’s importanceFollow these reasons to know java’s importance
Follow these reasons to know java’s importance
 
React native
React nativeReact native
React native
 
Test stack
Test stackTest stack
Test stack
 
YeurDreamin' - Put the Wow! into your Flow with Lightning Experience
YeurDreamin'  - Put the Wow! into your Flow with Lightning ExperienceYeurDreamin'  - Put the Wow! into your Flow with Lightning Experience
YeurDreamin' - Put the Wow! into your Flow with Lightning Experience
 

Similar to Writing Performant Front-end Code

Riereta Node.js session 3 (with notes)
Riereta Node.js session 3 (with notes)Riereta Node.js session 3 (with notes)
Riereta Node.js session 3 (with notes)Tekno Paul
 
Node.JS Expreee.JS scale webapp on Google cloud
Node.JS Expreee.JS scale webapp on Google cloudNode.JS Expreee.JS scale webapp on Google cloud
Node.JS Expreee.JS scale webapp on Google cloudJimish Parekh
 
The Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and EverythingThe Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and EverythingAndrey Karpov
 
The Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and EverythingThe Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and EverythingPVS-Studio
 
C++ on the Web: Run your big 3D game in the browser
C++ on the Web: Run your big 3D game in the browserC++ on the Web: Run your big 3D game in the browser
C++ on the Web: Run your big 3D game in the browserAndre Weissflog
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll buildMark Stoodley
 
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneWhen Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneDavid Glick
 
Intro to Node.js (for .NET Developers)
Intro to Node.js (for .NET Developers)Intro to Node.js (for .NET Developers)
Intro to Node.js (for .NET Developers)David Neal
 
Checking the Source SDK Project
Checking the Source SDK ProjectChecking the Source SDK Project
Checking the Source SDK ProjectAndrey Karpov
 
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...mCloud
 
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...Hafez Kamal
 
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.UA Mobile
 
2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with BlackfireMarko Mitranić
 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...andreaslubbe
 
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...DevSecCon
 
WordPress automation and CI
WordPress automation and CIWordPress automation and CI
WordPress automation and CIRan Bar-Zik
 

Similar to Writing Performant Front-end Code (20)

Riereta Node.js session 3 (with notes)
Riereta Node.js session 3 (with notes)Riereta Node.js session 3 (with notes)
Riereta Node.js session 3 (with notes)
 
Node.JS Expreee.JS scale webapp on Google cloud
Node.JS Expreee.JS scale webapp on Google cloudNode.JS Expreee.JS scale webapp on Google cloud
Node.JS Expreee.JS scale webapp on Google cloud
 
Node.js
Node.jsNode.js
Node.js
 
The Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and EverythingThe Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and Everything
 
The Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and EverythingThe Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and Everything
 
C++ on the Web: Run your big 3D game in the browser
C++ on the Web: Run your big 3D game in the browserC++ on the Web: Run your big 3D game in the browser
C++ on the Web: Run your big 3D game in the browser
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll build
 
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneWhen Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
 
Intro to Node.js (for .NET Developers)
Intro to Node.js (for .NET Developers)Intro to Node.js (for .NET Developers)
Intro to Node.js (for .NET Developers)
 
Checking the Source SDK Project
Checking the Source SDK ProjectChecking the Source SDK Project
Checking the Source SDK Project
 
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
 
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
 
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
 
Web Leaps Forward
Web Leaps ForwardWeb Leaps Forward
Web Leaps Forward
 
2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire
 
Cucumber - Maria Machlowska
Cucumber - Maria MachlowskaCucumber - Maria Machlowska
Cucumber - Maria Machlowska
 
10 Ways To Improve Your Code
10 Ways To Improve Your Code10 Ways To Improve Your Code
10 Ways To Improve Your Code
 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
 
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
 
WordPress automation and CI
WordPress automation and CIWordPress automation and CI
WordPress automation and CI
 

Recently uploaded

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 

Recently uploaded (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Writing Performant Front-end Code

  • 1. V I R T U A L C O N F E R E N C E / / N O V - D E C 2 0 2 0 / / P R E S E N T E D B Y E P A M
  • 2. V I R T U A L C O N F E R E N C E / / N O V - D E C 2 0 2 0 / / P R E S E N T E D B Y E P A M Writing Performant Front-end Code LY U B O M I R B O Z H I N O V
  • 3. ADAPT BY ZED Who Am I? Lyu b omir B ozh in ov Lead Software Engineer Lead Software Engineer @ EPAM. Author. Speaker. But most importantly, a tinkerer at heart, who believes one should always leave the code better than they found it - and apply the same to everything. 3 About Me
  • 4. 4 About Me So, yeah, I write code for a living.
  • 5. 5 About Me Sometimes I even know why it works!
  • 6. ADAPT BY ZED • MAKE IT WORK • MAKE IT FAST • MAKE IT PRETTY 6 Intro
  • 7. ADAPT BY ZED • MAKE IT WORK • MAKE IT FAST • MAKE IT PRETTY HOW OFTEN DO YOU IGNORE CODE PERFORMANCE? 7 Intro
  • 8. Level Zero: Code Performance The Art of the Tinkerer 1
  • 9. ADAPT BY ZED 9 Computational Complexity: Time v Space Sometimes the best way to visualise something is with a poor drawing of random ‘wibbly-wobbly’ lines.
  • 10. ADAPT BY ZED 10 Computational Complexity: The Problem In the classic find all anagrams in a dataset problem, you could iterate every time. Or just pre-process and use KVPs. v
  • 11. ADAPT BY ZED 11 Computational Complexity: Time v Space Hungry, hungry Chrome tabs!
  • 12. ADAPT BY ZED 12 Computational Complexity: Time v Space CompSci101 Reference
  • 13. 13 Premature Optimisation What do I mean by that? Basically any situation where one tries to make the code run faster before even having completed the functionality.
  • 14. 14 Level Zero Fast? Speed can be weird at this level.
  • 15. 15 Measure! Measure your code speed! And do it with enough consistency across the codebase to have an early-warning system for performance problems.
  • 16. 16 Measure How? USER TIMING API MARKS & MEASURES https://developer.mozilla.org/en- US/docs/Web/API/User_Timing_API
  • 18. ADAPT BY ZEDLevel Zero: How & Why? 18 WHY MEASURE LOG TINKER RINSE REPEAT SLOW CODE IS BAD HOW
  • 20. ADAPT BY ZED Our favourite language in the multiverse is single-threaded.  20 The Event Loop
  • 21. ADAPT BY ZED The Pixel Pipeline. Source: web.dev 21 The Pixel Pipeline
  • 22. Say ‘hello’ to your new best friend! 22 The Performance Tab
  • 23. 23 Optimise Your JS Your code drives the entire pipeline!
  • 24. ADAPT BY ZED Changing an element’s width or class will trigger visual changes. ‘It’s only logical.’ 24 Optimise Your JS
  • 25. ADAPT BY ZED Anything small that will trigger a visual update should be done in a RAF call to ensure it’s finished on time. No setTimeout! 25 Optimise Your JS
  • 26. ADAPT BY ZED Split the work into smaller tasks, push them onto a stack, and then use RAF calls to deal with them one by one. 26 Optimise Your JS
  • 27. ADAPT BY ZED Just spin up a web worker to keep the main thread free of the long-running computation. 27 Optimise Your JS
  • 28. ADAPT BY ZED The possibilities are endless. 28 Optimise Your JS
  • 29. ADAPT BY ZED Jason Miller (@developit) 29 Optimise Your JS greenlet: https://www.npmjs.com/package/greenlet workerize: https://www.npmjs.com/package/workerize-loader
  • 30. 30 Improve Style Calculations We all joke around that CSS is a necessary evil, but the reality is that we simply MUST try to keep it in check.
  • 31. 31 Improve Style Calculations SMACSS: http://smacss.com/ BEM: http://getbem.com/introduction/ https://www.smashingmagazine.com/20 13/10/challenging-css-best-practices- atomic-approach/
  • 32. 32 Minimise Layout Complexity The fewer elements you have in your DOM tree, the more quickly the browser will calculate the locations and dimensions of all of them.
  • 33. 33 Paint and Compositing • All property changes except transform and opacity will trigger a repaint. • Identify excessive paints with the dev tools and create a separate layer. • But too many layers at the compositing stage can have a performance impact.
  • 34. ADAPT BY ZED The four parts of the RAIL model are basically four perspectives on a web app’s state. Picture source: web.dev 34 The RAIL Model
  • 35. ADAPT BY ZEDThe RAIL Model 35 10ms50ms
  • 36. ADAPT BY ZED Source: web.dev 36 The RAIL Model
  • 37. ADAPT BY ZEDLevel One: How & Why? 37 WHY THE PERFORMANCE TAB OPTIMISE JAVASCRIPT EXECUTION IMPROVE STYLE CALCULATIONS MINIMISE LAYOUT COMPLEXITY SIMPLIFY PAINT AND MANAGE LAYERS KEEP THE RAIL MODEL IN MIND VISUAL JANK AND STUTTER IS JUST BAD UX SLOW RENDERING WILL MAKE THE USER FRUSTRATED HOW
  • 38. Level Two: Framework and Bundle Optimise Everything! 3
  • 39. ADAPT BY ZED There are number of other auto-magical features in modern frameworks – usually just a boolean flag in a JSON file. 39 The Pros and Cons of Frameworks
  • 40. ADAPT BY ZED I’ve had the misfortune to write jQuery in IE6. It was about as fun as it sounds. 40 The Pros and Cons of Frameworks
  • 41. ADAPT BY ZED Bundle analyzer: https://www.npmjs.com/package/webpack- bundle-analyzer 41 The Pros and Cons of Frameworks
  • 42. ADAPT BY ZED Redux + React 42 The Pros and Cons of Frameworks
  • 43. ADAPT BY ZED Preact + Unistore https://preactjs.com/ https://www.npmjs.com/package/unistore 43 The Pros and Cons of Frameworks
  • 44. ADAPT BY ZED Intro to PWAs: https://web.dev/progressive-web-apps 44 Going PWA
  • 46. ADAPT BY ZEDLevel Two: How & Why? 46 WHY ‘RIGHT TOOL FOR THE JOB’ TO ACHIEVE A GREAT USER EXPERIENCE HOW
  • 47. Level Three: The Network Waterfall Every Byte Matters 4
  • 48. ADAPT BY ZED It requires an absurd amount of tinkering to get it right. And the solution is different for every project. 48 The Network Waterfall
  • 49. ADAPT BY ZED Addy Osmani (@addyosmani) 49 Optimise Your JS critical: https://github.com/addyosmani/critical
  • 50. ADAPT BY ZEDLevel Three: How & Why? 50 WHY SOMEWHAT CLEAR CRYSTAL CLEAR HOW
  • 51. ADAPT BY ZED None of the things I’ve mentioned here today are FINAL. 51 Final Words
  • 52. 52 Final Words Largest Contentful Paint (LCP) First Input Delay (FID) Cumulative Layout Shift (CLS) Total Blocking Time (TBT) Keep an eye on https://web.dev
  • 53. V I R T U A L C O N F E R E N C E / / N O V - D E C 2 0 2 0 / / P R E S E N T E D B Y E P A M Thank you! LinkedIn: https://www.linkedin.com/in/lyubomir-bozhinov/ Twitter: https://twitter.com/TheElegantDev