When you are more comfortable with JavaScript it will be necessary to study a minimum the functioning of modern engines like V8, JS Core, SpiderMonkey etc (they are responsible for interpreting and executing your JavaScript code whether in Node.js or even in the browser).
This is clearly not an investment within the reach of a beginner but rather an intermediate or experienced developer 📚. To be able to better understand how your code will be managed and optimized it will therefore be necessary for you to learn the workings of the machine 😈.
Among the articles I strongly recommend you to read:
- [Beginner] How JavaScript works: an overview of the engine, the runtime, and the call stack
- [Intermediate] Whats up with monomorphism
- [Beginner] Shapes and Inline Caches
- [Beginner] optimizing prototypes
There are dozens of equally fascinating articles that I have taken the trouble to gather here: https://github.com/fraxken/VM-Resources
A few more talks for your enjoyment:
- JavaScript engines - how do they even?
- The Past, Present and Future of JavaScript Engines
- JavaScript Engines: The Good Parts
- A sneak peek into super optimized code in JS frameworks
- Embedding V8 in the real world by Stanimira Vlaeva
- Parsing JavaScript - better lazy than eager?
- Essentials of Interpretation
I think it's important to address the topic of benchmarks while we're in the engine JS section. Developers love to use them as an argument to justify various choices or ideologies 😰...
The problem is that most of the time these benchmarks are completely messed up and/or are not representative of a production workload 😂. Even if they are concrete you will need experience to deduce conclusions (and still nothing says that the concern concerns you otherwise).
Here are some articles to awaken you to the subject:
- Dangers of cross language benchmark games
- The trap of the performance sweet spot
- Performance tuning as the art of weather forecast
- The Black Cat of Microbenchmarks
- JavaScript MicroBenchmarks (from Benedikt Meurer)
- Preparing and Evaluating Benchmarks (from Rafael)
As hard as it may be to hear, I think that someone without a solid knowledge of how JavaScript engines work has no legitimacy to make conclusions based on benchmark results 💥.
“The hardest thing of all is to find which operation is more expensive inside the darkness of VM, especially when no operation is performed.” (Vyacheslav Egorov)
And even people with a lot of experience (including the contributors to the engines themselves) are always in doubt and prefer to take a pinch of salt for each of their conclusions. That's how difficult it is... whether you're going to do for-in, for-of or .forEach is not really relevant here.
“ 👉 Premature optimization is the root of all (or at least most) evils in programming..” (Donald Knuth)
⬅️ 🌌 Online courses, talks and articles | ➡️ ⚡ ECMAScript: JavaScript or ECMAScript ?