Hey people who know about browser implementations, what does a browser do when it comes across code like this? for (let i = 0; i < 100; i++) { const x = () => {} x() } Does it allocate memory for a new function every time or is it more fancy?
Replying to @gokul_i @kentcdodds
Mathias Bynens Retweeted Ben Smith
My colleague @binjimint beat me to it:https://twitter.com/binjimint/status/1136042635943038976 …
Mathias Bynens added,
Ben Smith @binjimint
Replying to @kentcdodds
For a trivial closure like this, it seems that the function call is removed entirely in v8, though the loop remains. I tested it with the following JS, using `d8 --print-opt-code test.js`. The core of the loop produces x64 assembly (annotated) as shown here: pic.twitter.com/cdNoNQgwRJ
0 replies
1 retweet
13 likes
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.