What is the v8 engine in nodejs

青灯夜游
Release: 2021-11-23 13:47:49
Original
2818 people have browsed it

In nodejs, the V8 engine is the interpreter for JavaScript running and is a JavaScript engine; V8 is developed using "C" and is used in Google Chrome. Before running JavaScript, V8 will compile it into native machine code and use methods such as inline caching to improve performance.

What is the v8 engine in nodejs

The operating environment of this tutorial: windows7 system, nodejs version 12.19.0, DELL G3 computer.

NodeJS Overview

According to Baidu Encyclopedia,Node.jsis a JavaScript toolkit for writing high-performance network servers. Node.js is a platform that can quickly build network services and applications. The platform is based on Chrome's JavaScript runtime, which means that it actually encapsulates the Google V8 engine (used in the Google Chrome browser). The V8 engine executes Javascript very quickly and has very good performance.

NodeJS does not provide simple encapsulation and then provide API calls. If that were the case, then it would not be as popular as it is now. Node has optimized some special use cases and provided alternative APIs to make V8 run better in non-browser environments. For example, in a server environment, processing binary data is usually essential, but Javascript does not support this enough. Therefore, V8.Node adds the Buffer class to process binary data conveniently and efficiently. Therefore, Node not only simply uses V8, but also optimizes it to make it more powerful in various environments.

Just-in-time compilation JIT Overview

V8 uses just-in-time compilation technology (JIT) to directly compile JavaScript code into the machine code of the local platform. From a macro perspective, the steps are JavaScript source code -> abstract syntax tree -> local machine code, and the latter step only depends on the previous step. This is different from other interpreters. For example, the Java language needs to first compile the source code into bytecode, and then interpret and execute it for the JVM. The JVM selectively compiles part of the bytecode into local machine code during operation according to the optimization strategy. V8 does not generate intermediate code, it is compiled into machine code in one step, and the CPU starts execution. Compared with the method of generating intermediate code for interpretation and execution, V8's strategy saves one step, and the program will start running earlier. And executing compiled machine instructions is faster than interpreting and executing intermediate code. The disadvantage is that the lack of an intermediate representation of bytecode makes code optimization more difficult.

V8 Overview

V8 is a JavaScript engine that originally served the Google Chrome browser. It was released with the first version of Chrome and open sourced. Now it has many other users besides Chrome browser. Such as NodeJS, MongoDB, CouchDB, etc.

V8 is developed in C and used in Google Chrome. Before running JavaScript, instead of other JavaScript engines converting it into bytecode or interpreting it for execution, V8 compiles it into native machine code (IA-32, x86-64, ARM, or MIPS CPUs) and uses the following Methods such as inline caching can be used to improve performance. With these features, JavaScript programs run as fast as binary programs under the V8 engine.

V8 implements ECMAScript as specified in ECMA-262, version 3 running on Windows XP and Vista, Mac OS X 10.5 (Snow Leopard and Linux) using IA-32 or ARM processors.

V8 can run independently or be embedded into any C application. The project is hosted on Google Code [1] and is based on the BSD protocol. Any organization or individual can use its source code for their own projects.

For more node-related knowledge, please visit:nodejs tutorial!!

The above is the detailed content of What is the v8 engine in nodejs. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!