SlideShare a Scribd company logo
!Slow JS
A Programmer is to a Coder, to what a Designer is to a Production Artist…
Advanced
Intermediate
Beginner
Target Audience
• Data structure
 Object vs Array
• Memory management
 Scope chain
 Data access
 De-referencing
• JS event loop
 Event loop
 setTimeout/setInterval
• Loops
 Faster loops
• UI rendering(jQuery)
 jQuery selectors
 Minimize reflow
• Chrome developer tool
Agenda
Object vs Array
// optimized, length=3, index lookup
var a= [10,20,30];
//sparse array, length = 9, output: [undefined × 4, 44, undefined × 3, 55]
var b = []; b[4]= 44, b[8]=55;
//holed array, length=2, not good
var c = [21,22,23]; c[1]= null; delete c[2];
visit code samples
Memory management
 Scope chain
 Data access
 Functions
Scope Chain
Golden rule: Further into the chain slower the resolution
Things to read; with, try/catch, clousure
Execution Context
Scope
Scope Chain
0
1
Activation Object
this window
agruments [item]
Item {array}
div undefined
Global
document {object}
window {object}
Data Access
I am faster
Literals or local
variables > object
property access
root.foo.name >
root.foo.item.name
Functions
avoids unnecessarily running the initialization code
JS Event Loop
 Event loop
 setTimeout/setInterval
Event Loop
 single thread == one task at a time
 Non-Preemption
 Runtime contains a message queue. A function is
associated to each message.
 When the stack is empty, a message is taken out
of the queue and processed.
setTimeout/setInterval
• Puts execution at the end of the event queue.
• Timeout, in milliseconds, it will wait before putting to
queue.
• Doesn’t guarantee to execute the function just after
the timeout passed.
Faster Loops
• Reduce lookup
• Control condition + control variable
• Avoid for-in or for-each loop
Increaseinperformance
UI Rendering(jQuery)
 jQuery selectors
 Minimize reflow
jQuery Selectors
• Use IDs
• Give context
• Cache always
Reflow
Reflow is the process by which the geometry of the layout engine’s formatting
objects are computed.
-Chris Waterson, Mozilla
Dom manipulation is heavy
Do DOM manipulations off the document.
Change CSS, not styles
THANKS!!

More Related Content

Viewers also liked

The Total Economic Impact of Equinix Interconnection Solutions
The Total Economic Impact of Equinix Interconnection SolutionsThe Total Economic Impact of Equinix Interconnection Solutions
The Total Economic Impact of Equinix Interconnection Solutions
Equinix
 
E healthcare. Medical Cross-Enterprise Collaborative Platform.
E healthcare. Medical Cross-Enterprise Collaborative Platform.E healthcare. Medical Cross-Enterprise Collaborative Platform.
E healthcare. Medical Cross-Enterprise Collaborative Platform.
Vassily Buzuyev
 
A React Journey
A React JourneyA React Journey
A React Journey
LinkMe Srl
 
πληροφορικη παιδεια στο δημοτικο
πληροφορικη παιδεια στο δημοτικοπληροφορικη παιδεια στο δημοτικο
πληροφορικη παιδεια στο δημοτικοΣ.Ε.Π.Κ@
 
Imaginación
ImaginaciónImaginación
Imaginación
maherran
 
Appium solution
Appium solutionAppium solution
Appium solution
Nael Abd Eljawad
 
φύλλοGoogle docs
φύλλοGoogle docsφύλλοGoogle docs
φύλλοGoogle docs
Ευαγγελια Βαμβακα
 
建立 Sass 環境,透過 Node sass
建立 Sass 環境,透過 Node sass建立 Sass 環境,透過 Node sass
建立 Sass 環境,透過 Node sass
Chih-cheng Wang
 
React. Flux. Redux
React. Flux. ReduxReact. Flux. Redux
React. Flux. Redux
Andrey Kolodnitsky
 
如何運用Bootstrap 切版?
如何運用Bootstrap 切版?如何運用Bootstrap 切版?
如何運用Bootstrap 切版?
shiang huang
 
υπηρεσίες και εφαρμογές διαδικτύου
υπηρεσίες και εφαρμογές διαδικτύουυπηρεσίες και εφαρμογές διαδικτύου
υπηρεσίες και εφαρμογές διαδικτύου
Aris G
 
Developing Apps With React Native
Developing Apps With React NativeDeveloping Apps With React Native
Developing Apps With React Native
Alvaro Viebrantz
 
Διαχειρίζομαι το Πένθος Επιστρέφω στη ζωή
Διαχειρίζομαι το Πένθος   Επιστρέφω στη ζωήΔιαχειρίζομαι το Πένθος   Επιστρέφω στη ζωή
Διαχειρίζομαι το Πένθος Επιστρέφω στη ζωή
Αννα Παππα
 

Viewers also liked (13)

The Total Economic Impact of Equinix Interconnection Solutions
The Total Economic Impact of Equinix Interconnection SolutionsThe Total Economic Impact of Equinix Interconnection Solutions
The Total Economic Impact of Equinix Interconnection Solutions
 
E healthcare. Medical Cross-Enterprise Collaborative Platform.
E healthcare. Medical Cross-Enterprise Collaborative Platform.E healthcare. Medical Cross-Enterprise Collaborative Platform.
E healthcare. Medical Cross-Enterprise Collaborative Platform.
 
A React Journey
A React JourneyA React Journey
A React Journey
 
πληροφορικη παιδεια στο δημοτικο
πληροφορικη παιδεια στο δημοτικοπληροφορικη παιδεια στο δημοτικο
πληροφορικη παιδεια στο δημοτικο
 
Imaginación
ImaginaciónImaginación
Imaginación
 
Appium solution
Appium solutionAppium solution
Appium solution
 
φύλλοGoogle docs
φύλλοGoogle docsφύλλοGoogle docs
φύλλοGoogle docs
 
建立 Sass 環境,透過 Node sass
建立 Sass 環境,透過 Node sass建立 Sass 環境,透過 Node sass
建立 Sass 環境,透過 Node sass
 
React. Flux. Redux
React. Flux. ReduxReact. Flux. Redux
React. Flux. Redux
 
如何運用Bootstrap 切版?
如何運用Bootstrap 切版?如何運用Bootstrap 切版?
如何運用Bootstrap 切版?
 
υπηρεσίες και εφαρμογές διαδικτύου
υπηρεσίες και εφαρμογές διαδικτύουυπηρεσίες και εφαρμογές διαδικτύου
υπηρεσίες και εφαρμογές διαδικτύου
 
Developing Apps With React Native
Developing Apps With React NativeDeveloping Apps With React Native
Developing Apps With React Native
 
Διαχειρίζομαι το Πένθος Επιστρέφω στη ζωή
Διαχειρίζομαι το Πένθος   Επιστρέφω στη ζωήΔιαχειρίζομαι το Πένθος   Επιστρέφω στη ζωή
Διαχειρίζομαι το Πένθος Επιστρέφω στη ζωή
 

Similar to Make JavaScript Faster

DIY Java Profiling
DIY Java ProfilingDIY Java Profiling
DIY Java Profiling
Roman Elizarov
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Haribabu Nandyal Padmanaban
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
Mats Bryntse
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletonGeorge Nguyen
 
(CMP305) Deep Learning on AWS Made EasyCmp305
(CMP305) Deep Learning on AWS Made EasyCmp305(CMP305) Deep Learning on AWS Made EasyCmp305
(CMP305) Deep Learning on AWS Made EasyCmp305
Amazon Web Services
 
DockerCon Europe 2018 Monitoring & Logging Workshop
DockerCon Europe 2018 Monitoring & Logging WorkshopDockerCon Europe 2018 Monitoring & Logging Workshop
DockerCon Europe 2018 Monitoring & Logging Workshop
Brian Christner
 
Q con shanghai2013-罗婷-performance methodology
Q con shanghai2013-罗婷-performance methodologyQ con shanghai2013-罗婷-performance methodology
Q con shanghai2013-罗婷-performance methodologyMichael Zhang
 
gDayX - Advanced angularjs
gDayX - Advanced angularjsgDayX - Advanced angularjs
gDayX - Advanced angularjsgdgvietnam
 
Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2
PawanMM
 
Hibernate - Part 1
Hibernate - Part 1Hibernate - Part 1
Hibernate - Part 1
Hitesh-Java
 
Grails and Ajax
Grails and AjaxGrails and Ajax
Grails and Ajax
TO THE NEW | Technology
 
Hibernate - Part 2
Hibernate - Part 2 Hibernate - Part 2
Hibernate - Part 2
Hitesh-Java
 
Droidcon Paris 2015
Droidcon Paris 2015Droidcon Paris 2015
Droidcon Paris 2015
Renaud Boulard
 
Why GC is eating all my CPU?
Why GC is eating all my CPU?Why GC is eating all my CPU?
Why GC is eating all my CPU?
Roman Elizarov
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
Ortus Solutions, Corp
 
Appsec usa2013 js_libinsecurity_stefanodipaola
Appsec usa2013 js_libinsecurity_stefanodipaolaAppsec usa2013 js_libinsecurity_stefanodipaola
Appsec usa2013 js_libinsecurity_stefanodipaoladrewz lin
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AI
Udaiappa Ramachandran
 
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh  - Some new vulnerabilities in modern web applicationNguyen Phuong Truong Anh  - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
Security Bootcamp
 
Learning Predictive Modeling with TSA and Kaggle
Learning Predictive Modeling with TSA and KaggleLearning Predictive Modeling with TSA and Kaggle
Learning Predictive Modeling with TSA and Kaggle
Yvonne K. Matos
 
AppFabric Velocity
AppFabric VelocityAppFabric Velocity
AppFabric Velocity
Dennis van der Stelt
 

Similar to Make JavaScript Faster (20)

DIY Java Profiling
DIY Java ProfilingDIY Java Profiling
DIY Java Profiling
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
 
(CMP305) Deep Learning on AWS Made EasyCmp305
(CMP305) Deep Learning on AWS Made EasyCmp305(CMP305) Deep Learning on AWS Made EasyCmp305
(CMP305) Deep Learning on AWS Made EasyCmp305
 
DockerCon Europe 2018 Monitoring & Logging Workshop
DockerCon Europe 2018 Monitoring & Logging WorkshopDockerCon Europe 2018 Monitoring & Logging Workshop
DockerCon Europe 2018 Monitoring & Logging Workshop
 
Q con shanghai2013-罗婷-performance methodology
Q con shanghai2013-罗婷-performance methodologyQ con shanghai2013-罗婷-performance methodology
Q con shanghai2013-罗婷-performance methodology
 
gDayX - Advanced angularjs
gDayX - Advanced angularjsgDayX - Advanced angularjs
gDayX - Advanced angularjs
 
Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2
 
Hibernate - Part 1
Hibernate - Part 1Hibernate - Part 1
Hibernate - Part 1
 
Grails and Ajax
Grails and AjaxGrails and Ajax
Grails and Ajax
 
Hibernate - Part 2
Hibernate - Part 2 Hibernate - Part 2
Hibernate - Part 2
 
Droidcon Paris 2015
Droidcon Paris 2015Droidcon Paris 2015
Droidcon Paris 2015
 
Why GC is eating all my CPU?
Why GC is eating all my CPU?Why GC is eating all my CPU?
Why GC is eating all my CPU?
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
Appsec usa2013 js_libinsecurity_stefanodipaola
Appsec usa2013 js_libinsecurity_stefanodipaolaAppsec usa2013 js_libinsecurity_stefanodipaola
Appsec usa2013 js_libinsecurity_stefanodipaola
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AI
 
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh  - Some new vulnerabilities in modern web applicationNguyen Phuong Truong Anh  - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
 
Learning Predictive Modeling with TSA and Kaggle
Learning Predictive Modeling with TSA and KaggleLearning Predictive Modeling with TSA and Kaggle
Learning Predictive Modeling with TSA and Kaggle
 
AppFabric Velocity
AppFabric VelocityAppFabric Velocity
AppFabric Velocity
 

Recently uploaded

Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
Google
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
abdulrafaychaudhry
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 

Recently uploaded (20)

Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 

Make JavaScript Faster

  • 1. !Slow JS A Programmer is to a Coder, to what a Designer is to a Production Artist…
  • 3. • Data structure  Object vs Array • Memory management  Scope chain  Data access  De-referencing • JS event loop  Event loop  setTimeout/setInterval • Loops  Faster loops • UI rendering(jQuery)  jQuery selectors  Minimize reflow • Chrome developer tool Agenda
  • 4. Object vs Array // optimized, length=3, index lookup var a= [10,20,30]; //sparse array, length = 9, output: [undefined × 4, 44, undefined × 3, 55] var b = []; b[4]= 44, b[8]=55; //holed array, length=2, not good var c = [21,22,23]; c[1]= null; delete c[2]; visit code samples
  • 5. Memory management  Scope chain  Data access  Functions
  • 6. Scope Chain Golden rule: Further into the chain slower the resolution Things to read; with, try/catch, clousure Execution Context Scope Scope Chain 0 1 Activation Object this window agruments [item] Item {array} div undefined Global document {object} window {object}
  • 7. Data Access I am faster Literals or local variables > object property access root.foo.name > root.foo.item.name
  • 8. Functions avoids unnecessarily running the initialization code
  • 9. JS Event Loop  Event loop  setTimeout/setInterval
  • 10. Event Loop  single thread == one task at a time  Non-Preemption  Runtime contains a message queue. A function is associated to each message.  When the stack is empty, a message is taken out of the queue and processed.
  • 11. setTimeout/setInterval • Puts execution at the end of the event queue. • Timeout, in milliseconds, it will wait before putting to queue. • Doesn’t guarantee to execute the function just after the timeout passed.
  • 12. Faster Loops • Reduce lookup • Control condition + control variable • Avoid for-in or for-each loop Increaseinperformance
  • 13. UI Rendering(jQuery)  jQuery selectors  Minimize reflow
  • 14. jQuery Selectors • Use IDs • Give context • Cache always
  • 15. Reflow Reflow is the process by which the geometry of the layout engine’s formatting objects are computed. -Chris Waterson, Mozilla Dom manipulation is heavy Do DOM manipulations off the document. Change CSS, not styles

Editor's Notes

  1. When lookup() called. It will have its scope associated. This will contain property which is global to this function. When execution starts an execution context will be created. Its scope chain will be initialized by picking from function context scope property. Then an activation object will be created having all local objects in it. Add it higher up in the scope chain Identifier resolution Resolution starts from scope chain 0
  2. literals or local variables > object properties or arrays root.foo.name > root.foo.item.name