Join the DZone community and get the full member experience.Join For Free
Lars Bak, danish programmer, the tech lead of V8 project
V8 is written in C++, and can run standalone or be embedded into the C++ app.
It is portable and runs on:
- Windows 7 or later
- macOS 10.12+
- Linux systems using x64, IA-32, MIPS and ARM processor
- SpiderMonkey - Firefox
- Chakra JS - Microsoft Edge
It doesn't matter if you run it in the browser or Node.js or an IoT device: to go from something that you write to executing that - that's what the engines are doing. JS engines are the heart of everything that we do.Franziska Hinkelmann, Senior Engineer at Google
Prehistory: Let's Start the Engine
This open-source JS engine came into being with the Chromium Project for Google Chrome and more Chromium browsers. Lars Bak, a danish programmer, was a project's creator and he's the one who led the V8
team. This man is a true virtual machine expert and guru of object-oriented design. By the way, Lars Bak spent 30 years developing programming languages. Once upon a time, he implemented a runtime system for BETA. Since then, Mr. Bak has left marks on a dramatic list of different software systems and finally get to the V8. How it was?
Supported and financed by Google, V8 engine powers today a huge amount of server-side JS code.
P.S.: After V8 Lars Bak has already realized Dart and Toit and received the Dahl-Nygaard prize in 2018. Well, that track record sounds impressive!
What Goes on Under the Hood
It is іnteresting that V8's subprocesses are named in accordance with automotive details. That is not only a stylish brand idea. It's also a good way for users to gain insight into JS engine behavior.
I like how they changed the names of the processing of the V8 engine to stuff like "ignition" and "turbofan". It's easier to remember because it's like a car engine now.Ksee, YouTube user
In the basic terms, JS engine:
1. Taking your
2. The parser is generating an abstract syntax tree from the source
3. V8's interpreter is generating a bytecode from the syntax tree that a compiler can understand
4. V8's compiler is generating a graph from bytecode (replacing bytecode sections with optimized machine code)
5. And, ta-dah – executing!
And what is making code runs so fast? Let's consider some interesting V8's characteristics.
- Interpreted or compiled?
JS is usually perceived as an interpreted language, but its modern engines are much more than just interpreters in order to get a more performant execution. The basis of the V8 that allows a high-speed JS executing is the JIT (Just-In-Time) compiler optimizing code during runtime (not Ahead-Of-Time). It combines the best features of interpreters and compilers, mixing these steps and making translation and execution faster.
The first optimizing compiler of V8 was "FullCodegen". The newest and more advanced is "Turbofan". Its backend is used by the V8's low-level register-based interpreter called 'Ignition'. This combined Ignition+TurboFan pipeline was launched in 2017.
- Keep calm and maintain cleanliness
Over the past years, V8's developers worked on the garbage collection process improvement a lot. Finally, they implemented a 2 generation-based garbage collector (also known as a full GC) called "Orinoco". It applies the latest effective techniques to free the thread. Collector finds objects and data that are no longer referenced and collects them. This contributes to well-improved latency and page load, smoother animation, scrolling, and user interaction.
In 2018, the Chromium team started a project called V8 Lite. The main aim was a forcefully reducing memory usage.
Our philosophy is that if you make a quick feedback loop, from programming to receiving feedback from the running system, in under a second, it inspires the programmer to experiment and invent new things.Lars Bak, danish programmer, the tech lead of V8 project
All Roads Lead to Chrome
Published at DZone with permission of Alexandra Lozovyuk. See the original article here.
Opinions expressed by DZone contributors are their own.