JavaScript Engine V8 release v8.0 release arrives at Google Chrome a few weeks later

V8 released version 8.0, which, in addition to fixing some bugs, undoubtedly resulted in performance improvements. It’s currently in preview, and the official release will be released with Chrome 80 Stable in a few weeks. Let’s start with performance improvements, which include reduced memory footprint and speed improvements:

JavaScript Engine V8 release v8.0 release arrives at Google Chrome a few weeks later

Pointer compression

The V8 heap contains everything from floating-point values, string characters, compiled code, and tag values (tagged values), which represent pointers or small integers to the V8 heap, and the development team found that these tag values took up most of the heap’s space.

The tag values are as large as the system pointer, and for a 32-bit architecture they are 32-bit wide, compared to 64-bit in a 64-bit architecture. When you compare a 32-bit version to a 64-bit version, you use twice as much heap memory for each tag value.

This version reduces this piece of memory in one way: pointer compression. Because highs can be synthesized by lows, you can save memory resources by storing only unique lows in the heap, and after testing, you can save an average of 40% of heap memory.

JavaScript Engine V8 release v8.0 release arrives at Google Chrome a few weeks later

Speed performance is often sacrificed while reducing memory, but with this improvement, V8 and its garbage collector can see real site performance improvements.

JavaScript Engine V8 release v8.0 release arrives at Google Chrome a few weeks later

Optimize high-order built-in programs

This release eliminates a limitation in the TurboFan optimization pipeline that prevents optimization of higher-order built-in functions.

const charCodeAt = Function.prototype.call.bind(String.prototype.charCodeAt);charCodeAt(string, 8);

The call to TurboFan by charCodeAt is completely opaque, resulting in a generic call to a user-defined function. With this change, it is now possible to identify that the built-in String.prototype.charCodeAt function is actually being called, which can trigger all further optimizations in TurboFan inventory to improve calls to the built-in function, resulting in the same performance as the following code:

string.charCodeAt(8);

Javascript

There have also been changes in JavaScript features, bringing with them two new ones:

Chain Optionaling

When writing a property access chain, developers often need to check if the median value is empty (null or undefined), which can lead to a lengthy explicit error check chain.

// Error prone-version, could throw.const nameLength = db.user.name.length;// Less error-prone, but harder to read.let nameLength;if (db && db.user && db.user.name)  nameLength = db.user.name.length;

Chain Optionaling (?) Allows developers to write more reliable property access chains to check if the median value is empty. If the median value is empty, the entire expression is evaluated as undefined.

// Still checks for errors and is much more readable.const nameLength = db?.user?.name?.length;

At the same time, in addition to static property access, Optional Chaining supports dynamic property access and calling.

Nullish Coalescing

Another feature that is very close to Optional Chaining is null judgment merge, which is made up of a specific Nullish Coalescing operator. Enabled, it is a new short-circuit binary operator.

Now you sometimes use logic. Operators handle default values, such as:

functionComponent(props) {  const enable = props.enabled || true;  // …}

The operation of a b, when a is non-true, the result is b, and if props.enabled itself is explicitly set to “false”, then this operation will still get the second operation number “true”, i.e. true.

Now use the null merge operator??, when a is empty, that is, null or undefined, a ??? b the result is b, otherwise a, and this default processing behavior is logical, making up for the problem described earlier.

functionComponent(props) {  const enable = props.enabled ?? true;  // …}

At the same time, null merge operators and Optional Chaining are accessible features that work well together. They can further handle situations in the above example where no props parameters are passed in.

functionComponent(props) {  const enable = props?.enabled ?? true;  // …}

In addition, there are some changes to the API that can be viewed in the following ways:

git log branch-heads/7.9..branch-heads/8.0 include/v8.h

Update notes:

https://v8.dev/blog/v8-release-80

Add a Comment

Your email address will not be published. Required fields are marked *