Franziska Hinkelmann: JavaScript engines - how do they even? | JSConf EU
Why Stack Overflow recommends it
Stack Overflow users link it when answering questions about why JavaScript code runs fast or slow, since it explains JIT compilation and V8's optimization behavior such as type feedback and object shapes.
Recommended by 2 people across 2 different months, 2017 to 2023.
What it is
A 25-minute JSConf EU 2017 conference talk by Franziska Hinkelmann, a V8 engineer, on how JavaScript engines work. It covers basic compiler concepts, just-in-time compilation, the challenges modern JavaScript poses, and how to write compiler-friendly code.
What people said
Recommends Pablo Cesar Cordova Morales · 2017-05 · Stack Overflow · on “Memory usage of arrays”
You say that you get 4-5 columns, and where push your data is variable for 4-5 columns, I know that v8 web engine is optimum for same type objects, maybe you can force to have 5 columns always to optimize your process: [this video]
Recommends Samathingamajig · 2023-01 · Stack Overflow · on “Why is JS' recursive fibonacci function faster than so many other languages?”
JavaScript is JIT-Compiled (just-in-time compiled, at least most implementations are), meaning that if it sees a function is called a lot with the same data type arguments, it will optimize the code to use more native data types instead of treating everything as an abstract type. There's a talk by Franziska Hinkelmann called "JavaScript engines - how do they even?" [this video] that includes a lot more detail about how engines detect when to optimize and a bit more on how they do the optimization.
Cites E. rex · 2017-06 · Stack Overflow · on “V8 won't optimize more than 4 object types?”
So I was watching Franziska Hinkelmann's talk on the V8 engine [this video] . She comments at 20:03 that the V8 engine will not optimize if there are more than four object types. I am just starting out in node.js, so I don't have any experience in these matters, but four seems like a very low number. Wouldn't OO software usually involve more than four object types? I'm aware that V8 has limitations on the number of properties an object can have for fast processing (8, also seems low).
Cites Derek Pollard · 2018-06 · Stack Overflow · on “V8: Heterogeneous Array Literals”
From this blog post [LINK] provided by Mathias [LINK] , a V8 developer: Common elements kinds While running JavaScript code, V8 keeps track of what kind of elements each array contains. This information allows V8 to optimize any operations on the array specifically for this type of element. For example, when you call reduce, map, or forEach on an array, V8 can optimize those operations based on what kind of elements the array contains. Take this array, for example: const array = [1, 2, 3]; What kinds of elements does it contain? If you’d ask the typeof operator, it would tell you the array contains numbers. At the language-level, that’s all you get: JavaScript doesn’t distinguish between int
Cites P.B.UDAY · 2019-02 · Stack Overflow · on “NodeJS - Why are for loops faster when wrapped in a function than when not wrapped?”
If you try to run the function first, you will see that the loop inside the function now takes more time. This is to do more with how V8 engine that compiles the javascript works rather than just the code. There is a lot of optimization done under the covers to make the javascript code faster. One of which is the optimizing compiler. Since JS compiler is a "JUST IN TIME" compiler, it compiles the first piece of code then moves on to the second piece of code. The optimizing compiler finds similar variable declarations etc.. from the previous results. If it finds similar information it uses it else re-compiles. This image may help you understand how the re-compiler works: [LINK] Image from vid
Cites jmrk · 2019-03 · Stack Overflow · on “What does V8's ignition really do?”
V8 developer here. On [LINK] we can see that: Ignition is a fast low-level register-based interpreter written using the backend of TurboFan Yes, that sums it up. To add a little more detail: The name "Ignition" refers to both the Bytecode Generator and the Bytecode Interpreter. Often, the entire thing is also seen as one big black box and casually called "the interpreter", which can sometimes lead to a bit of confusion around the terms. The Bytecode Generator takes the AST produced by the Parser for a given JavaScript function, and generates bytecode from it. The Bytecode Interpreter takes the bytecode generated by the Bytecode Generator and executes it by interpreting it by sending it to a
Cites marzelin · 2019-03 · Stack Overflow · on “What does V8's ignition really do?”
On [LINK] we can see that: Ignition is a fast low-level register-based interpreter written using the backend of TurboFan on [LINK] The aim of the Ignition project is to build an interpreter for V8 which executes a low-level bytecode, thus enabling run-once or non-hot code to be stored more compactly in bytecode form. The interpreter itself consists of a set of bytecode handler code snippets, each of which handles a specific bytecode and dispatches to the handler for the next bytecode. These bytecode handlers To compile a function to bytecode, the JavaScript code is parsed to generate its AST (Abstract Syntax Tree). The BytecodeGenerator walks this AST and generates bytecode for each of the A