SlideShare a Scribd company logo
1 of 13
Download to read offline
JavaS cript Variable Performance
              Nicholas C . Zakas
   P rincipal Front E nd E ngineer, Yahoo!
S cope C hains
When a Function E xecutes
• An execution context is created
• The context's scope chain is initialized
  with the members of the function's
  [[S cope]] collection
• An activation object is created containing
  all local variables
• The activation object is pushed to the
  front of the context's scope chain
E xecution C ontext




Identifier R es olution
• S tart at scope chain position 0
• If not found go to position 1
• And so on
Identifier R es olution
• Local variables = fast!
• The further into the chain, the slower the
  resolution
Identifier R es olution (R eads )


                                                     Firefox 3
                                                     Firefox 3.1 Beta 2
                                                     Google Chrome 1
                                                     Internet Explorer 7
Time




                                                     Internet Explorer 8 Beta 2
                                                     Opera 9.62
                                                     Safari 3.1 (525.13)
                                                     Safari 3.2 (525.27.1)
                                                     WebKit Nightly (528+)




         1   2    3                      4   5   6
                      Identifier Depth
Identifier R es olution (Writes )


                                                    Firefox 3
                                                    Firefox 3.1 Beta 2
                                                    Google Chrome 1
                                                    Internet Explorer 7
Time




                                                    Internet Explorer 8 Beta 2
                                                    Opera 9.62
                                                    Safari 3.1 (525.13)
                                                    Safari 3.2 (525.27.1)
                                                    WebKit Nightly (528+)




         1   2   3                      4   5   6
                     Identifier Depth
R ecommendations
• S tore local references to out-of-scope
  variables
  – E specially global variables
• Avoid the with statement
  – Adds another object to the scope chain, so
    local function variables are now one step
    away
E tcetera
• M y blog:          www.nczonline.net
• M y email:         nzakas@ yahoo-inc.com
• Twitter:     @ slicknet

More Related Content

Similar to JavaScript Variable Performance

วิธีการ
วิธีการวิธีการ
วิธีการ
0897169760
 
Programs V1.8.3(V2.0beta)
Programs V1.8.3(V2.0beta)Programs V1.8.3(V2.0beta)
Programs V1.8.3(V2.0beta)
guestc6ca44
 
Firefox 3.1 in 3.1 minutes
Firefox 3.1 in 3.1 minutesFirefox 3.1 in 3.1 minutes
Firefox 3.1 in 3.1 minutes
Thomas Bassetto
 
State of Developer Tools (WDS09)
State of Developer Tools (WDS09)State of Developer Tools (WDS09)
State of Developer Tools (WDS09)
bgalbs
 
HTML5 and the Future of Apps
HTML5 and the Future of AppsHTML5 and the Future of Apps
HTML5 and the Future of Apps
Tom Croucher
 
Cldc Hotspot Architecture
Cldc Hotspot ArchitectureCldc Hotspot Architecture
Cldc Hotspot Architecture
zdmilan
 
ドワンゴでのScala活用事例「ニコニコandroid」
ドワンゴでのScala活用事例「ニコニコandroid」ドワンゴでのScala活用事例「ニコニコandroid」
ドワンゴでのScala活用事例「ニコニコandroid」
Satoshi Goto
 
หน่วยการเรียนรู้ที่ 4
หน่วยการเรียนรู้ที่ 4หน่วยการเรียนรู้ที่ 4
หน่วยการเรียนรู้ที่ 4
Papichaya Chengtong
 

Similar to JavaScript Variable Performance (20)

Mindquarry For Cocoon Users
Mindquarry For Cocoon UsersMindquarry For Cocoon Users
Mindquarry For Cocoon Users
 
Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Dock...
Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Dock...Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Dock...
Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Dock...
 
วิธีการ
วิธีการวิธีการ
วิธีการ
 
Programs V1.8.3(V2.0beta)
Programs V1.8.3(V2.0beta)Programs V1.8.3(V2.0beta)
Programs V1.8.3(V2.0beta)
 
Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...
Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...
Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...
 
Firefox 3.1 in 3.1 minutes
Firefox 3.1 in 3.1 minutesFirefox 3.1 in 3.1 minutes
Firefox 3.1 in 3.1 minutes
 
Powering the Next Generation Services with Java Platform - Spark IT 2010
Powering the Next Generation Services with Java Platform - Spark IT 2010Powering the Next Generation Services with Java Platform - Spark IT 2010
Powering the Next Generation Services with Java Platform - Spark IT 2010
 
jQuery Keynote - Fall 2010
jQuery Keynote - Fall 2010jQuery Keynote - Fall 2010
jQuery Keynote - Fall 2010
 
(元)コミュニティメンバーから見たMozilla / Firefoxの歴史と展望@Browser Workshop
(元)コミュニティメンバーから見たMozilla / Firefoxの歴史と展望@Browser Workshop(元)コミュニティメンバーから見たMozilla / Firefoxの歴史と展望@Browser Workshop
(元)コミュニティメンバーから見たMozilla / Firefoxの歴史と展望@Browser Workshop
 
State of Developer Tools (WDS09)
State of Developer Tools (WDS09)State of Developer Tools (WDS09)
State of Developer Tools (WDS09)
 
HTML5 and the Future of Apps
HTML5 and the Future of AppsHTML5 and the Future of Apps
HTML5 and the Future of Apps
 
Toster - Understanding the Rails Web Model and Scalability Options
Toster - Understanding the Rails Web Model and Scalability OptionsToster - Understanding the Rails Web Model and Scalability Options
Toster - Understanding the Rails Web Model and Scalability Options
 
Understanding the Rails web model and scalability options
Understanding the Rails web model and scalability optionsUnderstanding the Rails web model and scalability options
Understanding the Rails web model and scalability options
 
Firefox 3.5 Overview
Firefox 3.5 OverviewFirefox 3.5 Overview
Firefox 3.5 Overview
 
De Java 8 a Java 17
De Java 8 a Java 17De Java 8 a Java 17
De Java 8 a Java 17
 
Cldc Hotspot Architecture
Cldc Hotspot ArchitectureCldc Hotspot Architecture
Cldc Hotspot Architecture
 
ドワンゴでのScala活用事例「ニコニコandroid」
ドワンゴでのScala活用事例「ニコニコandroid」ドワンゴでのScala活用事例「ニコニコandroid」
ドワンゴでのScala活用事例「ニコニコandroid」
 
Micronaut Deep Dive - Devoxx Belgium 2019
Micronaut Deep Dive - Devoxx Belgium 2019Micronaut Deep Dive - Devoxx Belgium 2019
Micronaut Deep Dive - Devoxx Belgium 2019
 
หน่วยการเรียนรู้ที่ 4
หน่วยการเรียนรู้ที่ 4หน่วยการเรียนรู้ที่ 4
หน่วยการเรียนรู้ที่ 4
 
Server Day 2009: GlassFish 3 by Alexis Moussine-Pouchkine
Server Day 2009: GlassFish 3 by Alexis Moussine-PouchkineServer Day 2009: GlassFish 3 by Alexis Moussine-Pouchkine
Server Day 2009: GlassFish 3 by Alexis Moussine-Pouchkine
 

More from Nicholas Zakas

Browser Wars Episode 1: The Phantom Menace
Browser Wars Episode 1: The Phantom MenaceBrowser Wars Episode 1: The Phantom Menace
Browser Wars Episode 1: The Phantom Menace
Nicholas Zakas
 
JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)
Nicholas Zakas
 
JavaScript Timers, Power Consumption, and Performance
JavaScript Timers, Power Consumption, and PerformanceJavaScript Timers, Power Consumption, and Performance
JavaScript Timers, Power Consumption, and Performance
Nicholas Zakas
 
High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)
Nicholas Zakas
 

More from Nicholas Zakas (20)

Browser Wars Episode 1: The Phantom Menace
Browser Wars Episode 1: The Phantom MenaceBrowser Wars Episode 1: The Phantom Menace
Browser Wars Episode 1: The Phantom Menace
 
Enough with the JavaScript already!
Enough with the JavaScript already!Enough with the JavaScript already!
Enough with the JavaScript already!
 
The Pointerless Web
The Pointerless WebThe Pointerless Web
The Pointerless Web
 
JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)
 
JavaScript Timers, Power Consumption, and Performance
JavaScript Timers, Power Consumption, and PerformanceJavaScript Timers, Power Consumption, and Performance
JavaScript Timers, Power Consumption, and Performance
 
Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012
 
Maintainable JavaScript 2012
Maintainable JavaScript 2012Maintainable JavaScript 2012
Maintainable JavaScript 2012
 
High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)
 
Maintainable JavaScript 2011
Maintainable JavaScript 2011Maintainable JavaScript 2011
Maintainable JavaScript 2011
 
High Performance JavaScript 2011
High Performance JavaScript 2011High Performance JavaScript 2011
High Performance JavaScript 2011
 
Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)
 
YUI Test The Next Generation (YUIConf 2010)
YUI Test The Next Generation (YUIConf 2010)YUI Test The Next Generation (YUIConf 2010)
YUI Test The Next Generation (YUIConf 2010)
 
High Performance JavaScript (YUIConf 2010)
High Performance JavaScript (YUIConf 2010)High Performance JavaScript (YUIConf 2010)
High Performance JavaScript (YUIConf 2010)
 
High Performance JavaScript - Fronteers 2010
High Performance JavaScript - Fronteers 2010High Performance JavaScript - Fronteers 2010
High Performance JavaScript - Fronteers 2010
 
High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010
 
Performance on the Yahoo! Homepage
Performance on the Yahoo! HomepagePerformance on the Yahoo! Homepage
Performance on the Yahoo! Homepage
 
High Performance JavaScript - jQuery Conference SF Bay Area 2010
High Performance JavaScript - jQuery Conference SF Bay Area 2010High Performance JavaScript - jQuery Conference SF Bay Area 2010
High Performance JavaScript - jQuery Conference SF Bay Area 2010
 
Scalable JavaScript Application Architecture
Scalable JavaScript Application ArchitectureScalable JavaScript Application Architecture
Scalable JavaScript Application Architecture
 
Extreme JavaScript Compression With YUI Compressor
Extreme JavaScript Compression With YUI CompressorExtreme JavaScript Compression With YUI Compressor
Extreme JavaScript Compression With YUI Compressor
 
Maintainable JavaScript
Maintainable JavaScriptMaintainable JavaScript
Maintainable JavaScript
 

Recently uploaded

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

JavaScript Variable Performance

  • 1. JavaS cript Variable Performance Nicholas C . Zakas P rincipal Front E nd E ngineer, Yahoo!
  • 2.
  • 3.
  • 4. S cope C hains
  • 5. When a Function E xecutes • An execution context is created • The context's scope chain is initialized with the members of the function's [[S cope]] collection • An activation object is created containing all local variables • The activation object is pushed to the front of the context's scope chain
  • 6. E xecution C ontext Identifier R es olution • S tart at scope chain position 0 • If not found go to position 1 • And so on
  • 7. Identifier R es olution • Local variables = fast! • The further into the chain, the slower the resolution
  • 8. Identifier R es olution (R eads ) Firefox 3 Firefox 3.1 Beta 2 Google Chrome 1 Internet Explorer 7 Time Internet Explorer 8 Beta 2 Opera 9.62 Safari 3.1 (525.13) Safari 3.2 (525.27.1) WebKit Nightly (528+) 1 2 3 4 5 6 Identifier Depth
  • 9. Identifier R es olution (Writes ) Firefox 3 Firefox 3.1 Beta 2 Google Chrome 1 Internet Explorer 7 Time Internet Explorer 8 Beta 2 Opera 9.62 Safari 3.1 (525.13) Safari 3.2 (525.27.1) WebKit Nightly (528+) 1 2 3 4 5 6 Identifier Depth
  • 10. R ecommendations • S tore local references to out-of-scope variables – E specially global variables • Avoid the with statement – Adds another object to the scope chain, so local function variables are now one step away
  • 11.
  • 12.
  • 13. E tcetera • M y blog: www.nczonline.net • M y email: nzakas@ yahoo-inc.com • Twitter: @ slicknet