What is V8?
V8 is a JavaScript engine developed by Google in the German research and Development center. Open source and implemented in C + +. Can be used for JavaScript programs running on the client and server side.
V8 was designed to improve the execution efficiency of JavaScript scripts on browsers. To speed up, V8 translates JavaScript code into more efficient machine code execution, rather than using the interpreter as usual. Like most JavaScript engines today, such as SpiderMonkey or Rhino, V8 implements a JIT (just-in-time) compiler, The code can be compiled into machine code when executing JavaScript code, but the main difference between V8 is that it does not return a byte code or any intermediate code.
In this article, you can learn how V8 works to compile more optimized code. If you have asked yourself before, "Should I worry about the efficiency of JavaScript?" "Then I can borrow Daniel Clifford (the head of the V8 team) to answer you:" V8 not only make your program run faster, but also do things that you couldn't do before. "
Hide Class
JavaScript is a Protoptye-based language: No classes and objects are generated when running. JavaScript is also a dynamic language: types and types of information are ambiguous. So how to access types and attributes effectively is a major challenge for V8. For most JavaScript engines in the past, the approach was to store object properties through a dictionary-like data structure and to determine the location of properties through dynamic queries, but V8, V8 created an implicit class at run time.
The following example contains a "point" method and creates two "point" objects:
If the layout is the same, as in this case, then p and Q belong to the same hidden class created by the V8 engine. This highlights another advantage of using hidden classes: You can allow V8 to bring together objects of the same property. For example, the "P" and "Q" objects in the will use the same optimization code.
Now if you want to add a "Z" attribute to the "Q" object, what will V8 do with it? In fact, whenever a new attribute is defined in the Forgotten function, V8 creates a new hidden class and tracks the structural changes of the hidden class.
Whenever a new hidden class is created, the previous hidden fatigue will be replaced.
[Essay Classification]nodejs
V8 Engine Introduction