SlideShare a Scribd company logo
1 of 29
JavaScript
Performance Tricks
   Grgur Grisogono - @ggrgur
Evaluation

eval(foo)
   vs
(new Function(foo))()
Evaluation
                       eval(foo)
                       (new Function(foo))()
6,000
             5,256


4,500


3,000


1,500                       1,081


        97            79              110         160   42         47
   0
        Chrome 21     Firefox 12            IE8              IE7
String Concatenation
                                                   foo = foo + bar
                                                   foo += bar
                                                   [].join(’’)

20,000,000               18,817,419



15,000,000


             9,940,504
10,000,000

                                6,348,293

 5,000,000                                  4,503,838              4,191,713

                                                                                     1,359,961
                                                                               825,543
                                                    435,988   347,348                          443,218
        0
                Chrome 21             Firefox 12          IE9           Safari 5     iOS Safari 5.1.1
String Concatenation
                                      foo = foo + bar
                                      foo += bar
                                      [].join(’’)
                                      foo.concat(bar)
                                                             93,236,430




      56,781,122




  18,817,419             21,484,919


                     4,503,838                                                 5,878,675
                                            1,320,424
                                         347,348         1,493,283          443,218

Chrome 21          Firefox 12            IE9            Safari 5      iOS Safari 5.1.1
String Concatenation
                                            foo = foo + bar
                                            foo += bar
                                            [].join(’’)
                                            foo.concat(bar)
                                                                         93,236,430




            56,781,122




                               21,484,919

9,940,504
                  6,348,293                                  4,191,713                     5,878,675
                                      435,988         1,320,424                1,359,961

    Chrome 21            Firefox 12             IE9                Safari 5       iOS Safari 5.1.1
String Concatenation
String Concatenation
Loops
Loops
                      for loop         while loop

900,000


675,000


450,000


225,000


     0
          Chrome 21              Firefox 12         IE9
Nested Object
 Properties
Nested Object
               Properties
                         deep          shallow

60,000,000


45,000,000


30,000,000


15,000,000


        0
             Chrome 21          Firefox 12       Desktop Safari 5
Reuse Array Refs
                                         foo = [1]
                                         foo.length = 0; foo.push(1)


300,000,000


              221,911,826
225,000,000


150,000,000


 75,000,000

                            10,688,860        10,964,912 18,867,925
                                                                       1,311,286   1,670,314
         0
                   Chrome 21                       Firefox 12                  IE9
Reuse Array Refs
                           foo = [1]
                           foo.length = 0; foo.push(1)


                                          18,867,925                 1,670,314


                                                         1,311,286
221,911,826

                             10,964,912




              10,688,860

    Chrome 21                    Firefox 12                      IE9
Reuse Array Refs
                          foo = [1]
                          foo.length = 0; foo.push(1)


             49,678,120

                                                         2,493,830




                                             1,030,567
14,644,518




 Desktop Safari 5                       Mobile Safari iPhone 4S 5.1.1
Overusing Closures
Minimize Number of
      Events
Minimize Number of
      Events
Timers
0
                                                10 ms timer #1 started
     Time in ms




                                                Screen resized
10                 Main JS code execution
                                                Timer #1 has expired

20

                  Screen resize event handler   10 ms timer #2 started

30
                       Timer #1 handler         Timer #2 has expired


40                     Timer #2 handler         10ms timer #3 started


50

                       Timer #3 handler
Adding Elements To
      DOM
Adding Elements To
      DOM
Adding Elements To
      DOM
Adding Elements To
      DOM
Adding Elements To
               DOM
           innerHTML                  DOM methods/replaceChild
           DOM/cloneNode              DocumentFragment
15,000


11,250


 7,500


 3,750


    0
         Chrome 21 Firefox 12   IE8       Safari    Opera   Mobile Safari
Updating CSS Styles
Updating CSS Styles
                    style            cssText

70,000


52,500


35,000                                                     69,621
                            62,893
           58,388

                                     40,058
17,500


    0
                Chrome 21                     Firefox 12
Selectors
Selectors
      table                                #menu              .first
      li.first                              #menu .first        #menu > li.first
      div#div1 table #menu li.first

1,500,000


1,125,000


 750,000


 375,000


       0
             Chrome 21       Desktop Safari 5    Firefox 12          IE9
Questions?

More Related Content

What's hot

Coq Tutorial
Coq TutorialCoq Tutorial
Coq Tutorialtmiya
 
Becoming a better developer with EXPLAIN
Becoming a better developer with EXPLAINBecoming a better developer with EXPLAIN
Becoming a better developer with EXPLAINLouise Grandjonc
 
Deep dive to PostgreSQL Indexes
Deep dive to PostgreSQL IndexesDeep dive to PostgreSQL Indexes
Deep dive to PostgreSQL IndexesIbrar Ahmed
 
A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009Jordan Baker
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cythonAnderson Dantas
 

What's hot (6)

Coq Tutorial
Coq TutorialCoq Tutorial
Coq Tutorial
 
Becoming a better developer with EXPLAIN
Becoming a better developer with EXPLAINBecoming a better developer with EXPLAIN
Becoming a better developer with EXPLAIN
 
League of Graphs
League of GraphsLeague of Graphs
League of Graphs
 
Deep dive to PostgreSQL Indexes
Deep dive to PostgreSQL IndexesDeep dive to PostgreSQL Indexes
Deep dive to PostgreSQL Indexes
 
A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cython
 

Viewers also liked

The China Analyst March 2011
The China Analyst   March 2011The China Analyst   March 2011
The China Analyst March 2011Barryvanwyk
 
tori . michelle . keenan . austun . kevin
tori . michelle . keenan . austun . kevintori . michelle . keenan . austun . kevin
tori . michelle . keenan . austun . kevinlovelytori
 
SenchaCon: DJing with Sencha Touch
SenchaCon: DJing with Sencha Touch SenchaCon: DJing with Sencha Touch
SenchaCon: DJing with Sencha Touch Patrick Sheridan
 
Eenpondverenbloeifactorharrietkollen keywork-1
Eenpondverenbloeifactorharrietkollen keywork-1Eenpondverenbloeifactorharrietkollen keywork-1
Eenpondverenbloeifactorharrietkollen keywork-1Harriet Kollen
 
LA ATENCION
LA ATENCIONLA ATENCION
LA ATENCIONCSG
 
Hệ thống ngân hàng thương mại việt nam và những vấn đề đặt ra
Hệ thống ngân hàng thương mại việt nam và những vấn đề đặt raHệ thống ngân hàng thương mại việt nam và những vấn đề đặt ra
Hệ thống ngân hàng thương mại việt nam và những vấn đề đặt raAskSock Ngô Quang Đạo
 
Barcelona presentacio tampere antirumors
Barcelona presentacio tampere antirumorsBarcelona presentacio tampere antirumors
Barcelona presentacio tampere antirumorsThomas Jézéquel
 
Local Undocumented Migration Policy in the Municipality of Utrecht
Local Undocumented Migration Policy in the Municipality of UtrechtLocal Undocumented Migration Policy in the Municipality of Utrecht
Local Undocumented Migration Policy in the Municipality of UtrechtThomas Jézéquel
 
Javascript classes and scoping
Javascript classes and scopingJavascript classes and scoping
Javascript classes and scopingPatrick Sheridan
 
Migrant Integration in Japan
Migrant Integration in JapanMigrant Integration in Japan
Migrant Integration in JapanThomas Jézéquel
 
2013 09.9 urbact network workshop compressed
2013 09.9 urbact network workshop compressed2013 09.9 urbact network workshop compressed
2013 09.9 urbact network workshop compressedThomas Jézéquel
 
SenchaCon: Sencha Touch Custom Components
SenchaCon: Sencha Touch Custom Components SenchaCon: Sencha Touch Custom Components
SenchaCon: Sencha Touch Custom Components Patrick Sheridan
 

Viewers also liked (18)

The China Analyst March 2011
The China Analyst   March 2011The China Analyst   March 2011
The China Analyst March 2011
 
tori . michelle . keenan . austun . kevin
tori . michelle . keenan . austun . kevintori . michelle . keenan . austun . kevin
tori . michelle . keenan . austun . kevin
 
SenchaCon: DJing with Sencha Touch
SenchaCon: DJing with Sencha Touch SenchaCon: DJing with Sencha Touch
SenchaCon: DJing with Sencha Touch
 
Eenpondverenbloeifactorharrietkollen keywork-1
Eenpondverenbloeifactorharrietkollen keywork-1Eenpondverenbloeifactorharrietkollen keywork-1
Eenpondverenbloeifactorharrietkollen keywork-1
 
Teachertube
TeachertubeTeachertube
Teachertube
 
LA ATENCION
LA ATENCIONLA ATENCION
LA ATENCION
 
Hệ thống ngân hàng thương mại việt nam và những vấn đề đặt ra
Hệ thống ngân hàng thương mại việt nam và những vấn đề đặt raHệ thống ngân hàng thương mại việt nam và những vấn đề đặt ra
Hệ thống ngân hàng thương mại việt nam và những vấn đề đặt ra
 
Barcelona presentacio tampere antirumors
Barcelona presentacio tampere antirumorsBarcelona presentacio tampere antirumors
Barcelona presentacio tampere antirumors
 
Local Undocumented Migration Policy in the Municipality of Utrecht
Local Undocumented Migration Policy in the Municipality of UtrechtLocal Undocumented Migration Policy in the Municipality of Utrecht
Local Undocumented Migration Policy in the Municipality of Utrecht
 
Javascript classes and scoping
Javascript classes and scopingJavascript classes and scoping
Javascript classes and scoping
 
Migrant Integration in Japan
Migrant Integration in JapanMigrant Integration in Japan
Migrant Integration in Japan
 
Ciao intro
Ciao introCiao intro
Ciao intro
 
Inforln.com ERP LN 10.3 & 10.4 Configurable Contract Deliverables Enhancements
Inforln.com ERP LN 10.3 & 10.4 Configurable Contract Deliverables EnhancementsInforln.com ERP LN 10.3 & 10.4 Configurable Contract Deliverables Enhancements
Inforln.com ERP LN 10.3 & 10.4 Configurable Contract Deliverables Enhancements
 
Irrp pankratova
Irrp pankratovaIrrp pankratova
Irrp pankratova
 
Quản trị chiến lược chuẩn
Quản trị chiến lược chuẩnQuản trị chiến lược chuẩn
Quản trị chiến lược chuẩn
 
M1 uf1
M1 uf1M1 uf1
M1 uf1
 
2013 09.9 urbact network workshop compressed
2013 09.9 urbact network workshop compressed2013 09.9 urbact network workshop compressed
2013 09.9 urbact network workshop compressed
 
SenchaCon: Sencha Touch Custom Components
SenchaCon: Sencha Touch Custom Components SenchaCon: Sencha Touch Custom Components
SenchaCon: Sencha Touch Custom Components
 

More from Patrick Sheridan

5 new rules for product development
5 new rules for product development5 new rules for product development
5 new rules for product developmentPatrick Sheridan
 
SenchaCon: DJing with Sencha Touch
SenchaCon: DJing with Sencha Touch SenchaCon: DJing with Sencha Touch
SenchaCon: DJing with Sencha Touch Patrick Sheridan
 
Using Data Visualization to Create Rich Content Experiences - MarkLogic Webin...
Using Data Visualization to Create Rich Content Experiences - MarkLogic Webin...Using Data Visualization to Create Rich Content Experiences - MarkLogic Webin...
Using Data Visualization to Create Rich Content Experiences - MarkLogic Webin...Patrick Sheridan
 
Ext JS 4.0 components and layouts
Ext JS 4.0 components and layoutsExt JS 4.0 components and layouts
Ext JS 4.0 components and layoutsPatrick Sheridan
 
Ext JS 4.0 - Creating extensions, plugins and components
Ext JS 4.0 - Creating extensions, plugins and componentsExt JS 4.0 - Creating extensions, plugins and components
Ext JS 4.0 - Creating extensions, plugins and componentsPatrick Sheridan
 
Modus Create Corporate Capabilities
Modus Create Corporate CapabilitiesModus Create Corporate Capabilities
Modus Create Corporate CapabilitiesPatrick Sheridan
 

More from Patrick Sheridan (14)

5 new rules for product development
5 new rules for product development5 new rules for product development
5 new rules for product development
 
SenchaCon: DJing with Sencha Touch
SenchaCon: DJing with Sencha Touch SenchaCon: DJing with Sencha Touch
SenchaCon: DJing with Sencha Touch
 
Sencha Touch in Action
Sencha Touch in Action Sencha Touch in Action
Sencha Touch in Action
 
Web audio app preso
Web audio app presoWeb audio app preso
Web audio app preso
 
Rvrsit
RvrsitRvrsit
Rvrsit
 
Discover Music
Discover MusicDiscover Music
Discover Music
 
ExtJS Forms
ExtJS FormsExtJS Forms
ExtJS Forms
 
Intro to sencha touch 2
Intro to sencha touch 2Intro to sencha touch 2
Intro to sencha touch 2
 
HTML5 and Sencha Touch
HTML5 and Sencha TouchHTML5 and Sencha Touch
HTML5 and Sencha Touch
 
Using Data Visualization to Create Rich Content Experiences - MarkLogic Webin...
Using Data Visualization to Create Rich Content Experiences - MarkLogic Webin...Using Data Visualization to Create Rich Content Experiences - MarkLogic Webin...
Using Data Visualization to Create Rich Content Experiences - MarkLogic Webin...
 
Ext JS 4.0 components and layouts
Ext JS 4.0 components and layoutsExt JS 4.0 components and layouts
Ext JS 4.0 components and layouts
 
Ext JS 4.0 - Creating extensions, plugins and components
Ext JS 4.0 - Creating extensions, plugins and componentsExt JS 4.0 - Creating extensions, plugins and components
Ext JS 4.0 - Creating extensions, plugins and components
 
JavaScript Secrets
JavaScript SecretsJavaScript Secrets
JavaScript Secrets
 
Modus Create Corporate Capabilities
Modus Create Corporate CapabilitiesModus Create Corporate Capabilities
Modus Create Corporate Capabilities
 

Recently uploaded

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
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 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
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
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
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 Processorsdebabhi2
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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 Scriptwesley chun
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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
 
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, ...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 

Javascript Performance Tricks

  • 1. JavaScript Performance Tricks Grgur Grisogono - @ggrgur
  • 2. Evaluation eval(foo) vs (new Function(foo))()
  • 3. Evaluation eval(foo) (new Function(foo))() 6,000 5,256 4,500 3,000 1,500 1,081 97 79 110 160 42 47 0 Chrome 21 Firefox 12 IE8 IE7
  • 4. String Concatenation foo = foo + bar foo += bar [].join(’’) 20,000,000 18,817,419 15,000,000 9,940,504 10,000,000 6,348,293 5,000,000 4,503,838 4,191,713 1,359,961 825,543 435,988 347,348 443,218 0 Chrome 21 Firefox 12 IE9 Safari 5 iOS Safari 5.1.1
  • 5. String Concatenation foo = foo + bar foo += bar [].join(’’) foo.concat(bar) 93,236,430 56,781,122 18,817,419 21,484,919 4,503,838 5,878,675 1,320,424 347,348 1,493,283 443,218 Chrome 21 Firefox 12 IE9 Safari 5 iOS Safari 5.1.1
  • 6. String Concatenation foo = foo + bar foo += bar [].join(’’) foo.concat(bar) 93,236,430 56,781,122 21,484,919 9,940,504 6,348,293 4,191,713 5,878,675 435,988 1,320,424 1,359,961 Chrome 21 Firefox 12 IE9 Safari 5 iOS Safari 5.1.1
  • 10. Loops for loop while loop 900,000 675,000 450,000 225,000 0 Chrome 21 Firefox 12 IE9
  • 12. Nested Object Properties deep shallow 60,000,000 45,000,000 30,000,000 15,000,000 0 Chrome 21 Firefox 12 Desktop Safari 5
  • 13. Reuse Array Refs foo = [1] foo.length = 0; foo.push(1) 300,000,000 221,911,826 225,000,000 150,000,000 75,000,000 10,688,860 10,964,912 18,867,925 1,311,286 1,670,314 0 Chrome 21 Firefox 12 IE9
  • 14. Reuse Array Refs foo = [1] foo.length = 0; foo.push(1) 18,867,925 1,670,314 1,311,286 221,911,826 10,964,912 10,688,860 Chrome 21 Firefox 12 IE9
  • 15. Reuse Array Refs foo = [1] foo.length = 0; foo.push(1) 49,678,120 2,493,830 1,030,567 14,644,518 Desktop Safari 5 Mobile Safari iPhone 4S 5.1.1
  • 19. Timers 0 10 ms timer #1 started Time in ms Screen resized 10 Main JS code execution Timer #1 has expired 20 Screen resize event handler 10 ms timer #2 started 30 Timer #1 handler Timer #2 has expired 40 Timer #2 handler 10ms timer #3 started 50 Timer #3 handler
  • 24. Adding Elements To DOM innerHTML DOM methods/replaceChild DOM/cloneNode DocumentFragment 15,000 11,250 7,500 3,750 0 Chrome 21 Firefox 12 IE8 Safari Opera Mobile Safari
  • 26. Updating CSS Styles style cssText 70,000 52,500 35,000 69,621 62,893 58,388 40,058 17,500 0 Chrome 21 Firefox 12
  • 28. Selectors table #menu .first li.first #menu .first #menu > li.first div#div1 table #menu li.first 1,500,000 1,125,000 750,000 375,000 0 Chrome 21 Desktop Safari 5 Firefox 12 IE9

Editor's Notes

  1. About me - MC, Ext JS in Action SE, History, SDC, Sencha \n
  2. \n
  3. Hard to debug, slow, ... But sometimes necessary (JSON)\nMobile, JSON Decode\n54x faster\nops/sec benchmark.js (jsperf style)\n
  4. Dynamic array creation can be slow\n
  5. \n
  6. \n
  7. \n
  8. \n
  9. a=1 for minimal noise during benchmarks\n
  10. \n
  11. Straight forward, but let’s examine the impact\n
  12. \n
  13. \n
  14. 2000%\n\n
  15. 2000%\n\n
  16. \n
  17. Bubbling - delegation\nCommon for Ext JS / Sencha Touch DataView/List items\n
  18. Bubbling - delegation\nCommon for Ext JS / Sencha Touch DataView/List items\n
  19. Fight the unresponsive dialogue\nVisually speed up long tasks (esp with dom manipulation)\n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. CSS class selectors are the slowest, ID are the fastest\n
  29. \n