Title: Decreased performance in code running in Temporal Dead Zone · Issue #12568 · nodejs/node · GitHub
Open Graph Title: Decreased performance in code running in Temporal Dead Zone · Issue #12568 · nodejs/node
X Title: Decreased performance in code running in Temporal Dead Zone · Issue #12568 · nodejs/node
Description: 7.9.0: Linux mitsos-XPS-13-9360 4.10.0-19-generic #21~16.04.1-Ubuntu SMP Fri Apr 7 08:20:02 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux: Subsystem: **I have created a detailed Stack Overflow question here so I will quote it here to get some ...
Open Graph Description: 7.9.0: Linux mitsos-XPS-13-9360 4.10.0-19-generic #21~16.04.1-Ubuntu SMP Fri Apr 7 08:20:02 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux: Subsystem: **I have created a detailed Stack Overflow question h...
X Description: 7.9.0: Linux mitsos-XPS-13-9360 4.10.0-19-generic #21~16.04.1-Ubuntu SMP Fri Apr 7 08:20:02 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux: Subsystem: **I have created a detailed Stack Overflow question h...
Opengraph URL: https://github.com/nodejs/node/issues/12568
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Decreased performance in code running in Temporal Dead Zone","articleBody":"\u003c!--\r\nThank you for reporting an issue.\r\n\r\nThis issue tracker is for bugs and issues found within Node.js core.\r\nIf you require more general support please file an issue on our help\r\nrepo. https://github.com/nodejs/help\r\n\r\n\r\nPlease fill in as much of the template below as you're able.\r\n\r\nVersion: output of `node -v`\r\nPlatform: output of `uname -a` (UNIX), or version and 32 or 64-bit (Windows)\r\nSubsystem: if known, please specify affected core module name\r\n\r\nIf possible, please provide code that demonstrates the problem, keeping it as\r\nsimple and free of external dependencies as you are able.\r\n-->\r\n\r\n* **7.9.0**:\r\n* **Linux mitsos-XPS-13-9360 4.10.0-19-generic #21~16.04.1-Ubuntu SMP Fri Apr 7 08:20:02 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux**:\r\n* **Subsystem**:\r\n\r\n\u003c!-- Enter your issue details below this comment. -->\r\n\r\n**I have created a detailed Stack Overflow question [here](http://stackoverflow.com/questions/43540849/javascript-temporal-dead-zone-nodejs-7-9-0-performance-decrease) so I will quote it here to get some answers since I do not know the internal mechanichs...\r\n\r\n**Quoted Question:**\r\n\r\nI have noticed in an other [question](http://stackoverflow.com/questions/37792934/why-is-let-slower-than-var-in-a-for-loop-in-nodejs) the performance difference in loops while using `let` and `var` variables declaration.\r\n\r\n\r\nThe initial question is correctly answered that using `let` in the **for loop** is slower since `let` creates a new scope for each iteration to hold the value of `let` declared variable. More work to be done, so it is normal to be slower. Just as reference, I give the code and the results in NodeJS (7.9.0) execution time:\r\n\r\n*Please note that all javascript code below regards NodeJS version 7.9.0*\r\n\r\n**Regular Code:**\r\n\r\n 'use strict';\r\n console.time('var');\r\n for (var i = 0; i \u003c 100000000; i++) {}\r\n console.timeEnd('var');\r\n \r\n \r\n console.time('let');\r\n for (let j = 0; j \u003c 100000000; j++) {}\r\n console.timeEnd('let');\r\n\r\n**Output:**\r\n\r\n var: 55.792ms\r\n let: 247.123ms\r\n\r\nIn order to avoid the extra scope declaration for `j` in every iteration of the loop, we declare the `j` variable just before the loop. One would expect that this should now make the `let` loop performance match the one of `var`. **BUT NO!!!** This is the code and the result for reference:\r\n\r\n**Code with `let` defined before loop:**\r\n\r\n 'use strict';\r\n console.time('var');\r\n for (var i = 0; i \u003c 100000000; i++) {}\r\n console.timeEnd('var');\r\n \r\n \r\n console.time('let');\r\n let j;\r\n for (j = 0; j \u003c 100000000; j++) {}\r\n console.timeEnd('let');\r\n\r\n**Output:**\r\n\r\n var: 231.249ms\r\n\tlet: 233.485ms\r\n\r\nWe can see that, not only the `let` loop did not get any faster but also the `var` loop became as slow as the `let` one!!! The only explanation for this is that since we are not in any block or function, both variables are declared in the **global** module scope. However as referenced [here](http://exploringjs.com/es6/ch_variables.html#sec_temporal-dead-zone), the `let` declaration of the variable in the middle of the scope, creates a **temporal dead zone**, which leaves the variable `j` uninitialized, while the `var` initializes the variable as defined.\r\n\r\nSo running code in a temporal dead zone although the uninitialized variable is not referenced, must be quite slower....\r\n\r\nFinally to show the deference, we declare the `j` variable on top of the program to show the results of running it without the **temporal dead zone**.\r\n\r\n**Code without temporal dead zone:**\r\n\r\n 'use strict';\r\n let j;\r\n console.time('var');\r\n for (var i = 0; i \u003c 100000000; i++) {}\r\n console.timeEnd('var');\r\n \r\n \r\n console.time('let');\r\n for (j = 0; j \u003c 100000000; j++) {}\r\n console.timeEnd('let');\r\n\r\n**Output:**\r\n\r\n\tvar: 55.586ms\r\n\tlet: 55.009ms\r\n\r\n**Now both `let` and `var` loops have similar optimized performance!**\r\n\r\nDoes anyone know whether my assumption about temporal dead zone performance is correct, or provide a different explanation???\r\n\r\n","author":{"url":"https://github.com/mitsos1os","@type":"Person","name":"mitsos1os"},"datePublished":"2017-04-21T11:16:09Z","url":"https://github.com/nodejs/node/issues/12568"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d472c20c-9734-ad91-ae02-ea43433612cf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B2DC:ABE51:66833E:855AEF:6AED2DDF |
| html-safe-nonce | 7f5adafff8154eb15619b6a17fc990a1bf9790c36adf384fcefb0b807d92af7e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMkRDOkFCRTUxOjY2ODMzRTo4NTVBRUY6NkFFRDJEREYiLCJ2aXNpdG9yX2lkIjoiNzE4NzkyOTMwNDEyMzkxMTY0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 785ae2ebab89710aa87eee962f74c1fea5ecfe2529a316257aeb84ec2aa2cb4a |
| hovercard-subject-tag | issue:223354109 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/12568/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2bb6bc3961ac552ebbe3e23030fb8080a61c599acc5af6a51e0cd133dafb6ad8/nodejs/node/issues/12568 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2bb6bc3961ac552ebbe3e23030fb8080a61c599acc5af6a51e0cd133dafb6ad8/nodejs/node/issues/12568 |
| og:image:alt | 7.9.0: Linux mitsos-XPS-13-9360 4.10.0-19-generic #21~16.04.1-Ubuntu SMP Fri Apr 7 08:20:02 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux: Subsystem: **I have created a detailed Stack Overflow question h... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mitsos1os |
| hostname | github.com |
| expected-hostname | github.com |
| None | e51d0b7b5ab34b1688c05b54c3ed17b8658b2fa9bca973a9c740683ccb12cf4a |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 59ebb7b901cc154ecc179a44f266fcf69f343b30 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width