Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of the javascript engine

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the role of the javascript engine, the article is very detailed, has a certain reference value, interested friends must read it!

The JavaScript engine is used to convert javascript code into rapidly optimized code that can be interpreted by the browser. The engine is a kind of software converter that inputs the code and produces commands that conform to machine recognition and operation.

The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.

What is the use of javascript engine

The JavaScript engine is a virtual machine that specializes in processing JavaScript scripts and is generally included in web browsers.

When it comes to the Javascript engine, many people are both familiar and unfamiliar. Because although I write a lot of js code every day, I am not very familiar with its principle and operation mechanism. This does not show up when the system has sufficient resources, but it may arise when there are performance requirements or when compatibility is needed on different browsers. So it is necessary to understand how the engine works.

So what is an engine? Personally, in the computer field, an engine is a kind of software converter that inputs your code and produces commands that conform to machine identification and operation. In the case of javascript, the engine is responsible for parsing js code and compiling it into machine languages in different environments. However, because javascript is a dynamic interpretive language, the performance pressure of js engine will be very great, compared to compiled languages such as java,c++. Therefore, performance will be one of the core indicators of modern js engines.

At present, the mainstream js engines are Google chrome's V8 engine and JavascriptCore, both of which belong to the webkit core. Webkit was first proposed by Apple, and then attracted many companies to develop it with increasing influence. Then, due to differences of opinion, Google cut out webkit separately and developed its own chromium series of browsers, focusing on high performance, so we will see that a lot of performance optimization techniques have been introduced in V8, while JavascriptCore, which has always been the default engine of the webkit kernel, is also slowly optimizing iterations. Let's take a look at the specific similarities and differences.

V8 engine

First, let's take a look at the overall processing flow of V8:

The first step is to parse with a parser, generate an abstract syntax tree, and then use the full code generator of JIT (Just In Time) to generate local code. The full code generator (full-code generator) here is part of the JIT compiler, which is different from the bytecode intermediate result of JavaScriptCore. This design is mainly for performance considerations, but also triggers more time-consuming calculations in some scenarios.

The compilation result of the full code generator depends on the back-end implementation of different platforms, and the corresponding assembly code is generated, as shown in the following figure:

Another thing worth mentioning is the memory management of V8: it involves how to manage data fragmentation and garbage collection. The data plane uses the Zone class, which is the smallest unit scheduled by the engine, the whole block of access deletes the Zone area, and stores the same type of data type within the Zone. If you want to recycle the entire Zone memory block, the advantage of this is that you can efficiently handle a large number of similar operations, such as generating abstract syntax trees, but the disadvantage is also very obvious, the fragmented data structures in the Zone are difficult to clean up in time, resulting in increased memory consumption.

Garbage collection V8 for memory also adopts the classic three-classification method, which is divided into young generations, old generations and large objects. As shown in the following figure:

In V8, handles are used to mark the position of objects. The difference from pointers is that handles are generally operating system integer bytes, usually 4 or 8 bytes. The handle can generate the corresponding pointer address, or it can be saved directly for small integer data.

JavascriptCore engine

As the default webkit engine maintained by Apple, JavaScriptCore introduces a lot of Apple technologies, such as LLVM, DFG (Data-Flow Graph) JIT compiler. The biggest difference from V8 is that it does not generate native code directly after generating the abstract syntax tree, but generates cross-platform bytecode:

The bytecode is then parsed with an interpreter similar to the Java virtual machine.

In the memory management area, JavaScriptCore and V8 are similar, generational strategies and variants of Zone, JSGlobalData.

To sum up, V8 and JavaScriptCore, as the representatives of js engine, have their own characteristics in the development route, but their performance can not be bypassed and need to be continuously improved. With the promotion of HTML5 standard, more video and webgl rendering have been added. It is believed that the function of web engine will be more perfect in the near future.

These are all the contents of the article "what is the role of the javascript engine?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report