Top 8 Recent V8 Updates
Tags: v8, node
Published: 2024-03-13 15:19:44

V8 is the most popular JavaScript engine on the planet, supporting technologies such as Chrome and Node.js. The pace of V8's development is impressive, with multiple code commits a day and [major releases](https://v8.dev/docs/release-process) roughly every month.

Keeping up with updates isn't easy, but you've come to the right place! Here, we'll dig into the latest improvements and additions Google has made to the JavaScript engine.

Find out what the future of web development looks like!

## What Is V8?

[V8](https://v8.dev/) is a high-performance JavaScript engine developed by Google. Its purpose is to convert JavaScript code into machine code for execution by the underlying hardware. Primarily developed by the V8 team at Google, the engine focuses on speed and efficiency. In particular, it relies on just-in-time compilation and uses inline caching for high performance.

Thanks to V8, Chromium-based browsers and Node.js can run JavaScript code. [Deno](https://blog.appsignal.com/2023/11/01/what-do-deno-and-bun-bring-to-the-table.html) also relies on it for executing JavaScript, making V8 a major element in modern software development.

## V8 JavaScript Engine: Latest Updates

As you can tell from the [V8 repository](https://chromium.googlesource.com/v8/v8), development is fast-paced, with several commits within the same day. This means that bug fixes, enhancements, and new features are introduced daily.

## Top Recent V8 Updates

Time to find out the top 8 recent V8 updates of the past few months!

### 1. New JavaScript Features

JavaScript continues to evolve to meet the demands of modern development. New standardized features are frequently added to the language, and JavaScript engines must implement them.

In the latest iterations, V8 has added support for:

- **[`toWellFormed()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toWellFormed) string method**: Returns a string where all [lone surrogates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#utf-16_characters_unicode_code_points_and_grapheme_clusters) are replaced with the Unicode replacement character `U+FFFD`.
- **[`isWellFormed()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/isWellFormed) string method**: Returns a boolean to indicate whether the string contains any lone surrogates.
- **[Resizable `ArrayBuffer`s](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer#resizing_arraybuffers)**: The `ArrayBuffer()` constructor now accepts the `maxByteLength` to define its maximum size in bytes. You can then assign a new size to a resizable `ArrayBuffer` object with the [`resize()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resize) method. This makes `ArrayBuffer`s more efficient and closer to WebAssembly.
- **[`ArrayBuffer` transfer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)**: `ArrayBuffer` objects can now be transferred between different execution contexts via the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).
- **RegExp [`v`](https://v8.dev/features/regexp-v-flag) flag**: A new mode that unlocks support for extended character classes, such as all valid emojis.
- **[`Object.groupBy()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/groupBy) static method for `Array`s**: To group the elements of a given iterable according to the given callback function.
- **[`Array.fromAsync()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync) static method**: Creates a new, shallow-copied `Array` instance from an [`async`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols) iterable, iterable, or array-like object.
- **[`Promise.withResolvers()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers) static method**: Returns an object containing a new `Promise` object and two functions to resolve or reject it.

Plus, dynamic `import()` has been updated to accept a [`with`](https://v8.dev/features/import-attributes) option to specify import attributes:

```javascript
const jsonModule = await import("./data.json", {
  // specify some extra attributes with through
  // the "with" object
  with: { type: "json" },
});
```

### 2. Support for Compilation to WebAssembly of Garbage Collected Languages

WasmGC, short for [WebAssembly Garbage Collection](https://developer.chrome.com/blog/wasmgc), represents a pivotal advancement in the realm of WebAssembly (Wasm). Its goal is the compilation of garbage-collected (GC) languages down to WasmGC constructs to make them run on the web.

After several years of work, [WasmGC is finally ready](https://v8.dev/blog/wasm-gc-porting).

Wasm now has a built-in way to allocate objects and arrays that are managed by the V8 garbage collector.

This enables compiling applications written in Java, Kotlin, Dart, Python, C#, and similar garbage-collected languages to Wasm.

That's a huge leap toward bringing GC languages efficiently to the web!

### 3. A Brand New Optimizing Compiler

The recent V8 update has introduced a brand-new optimizing compiler called [Maglev](https://v8.dev/blog/maglev). This solution sits between the [Sparkplug](https://v8.dev/blog/sparkplug) non-optimizing JavaScript compiler and the [TurboFan](https://v8.dev/docs/turbofan) top-tier optimizing compiler.

Maglev falls somewhere between these two as a high-speed optimizing compiler. It can generate code nearly 20 times slower than Sparkplug, but 10 to 100 times faster than TurboFan.

Thanks to Maglev, the team behind V8 has noticed the following performance improvements on JavaScript and WebAssembly benchmark sites:

- +8.2% on JetStream
- +6% on Speedometer

For more information, read [Maglev — V8’s Fastest Optimizing JIT](https://v8.dev/blog/maglev).

### 4. A New Architecture for the Optimizing Compiler Turbofan

Maglev is not the only investment the development team has made in compiler technologies. The latest V8 updates have also introduced Turboshaft, a new internal architecture for the high-level optimizing compiler Turbofan.

This new, modern, better-engineered architecture makes Turbofan easier to extend with new optimizations and faster compilation.

In fact, compilation times are twice as fast in certain situations.

That also leads to power savings, paving the way for other performance gains in the future.

### 5. Improved Security with Control-flow Integrity

CFI, short for [Control-flow Integrity](https://v8.dev/blog/control-flow-integrity), is a vital security feature designed to thwart exploits aimed at hijacking the control flow of a program.

By applying strict controls on how control flow instructions are executed, CFI prevents attackers from exploiting memory corruption vulnerabilities to execute arbitrary code. Thus, even if an attacker succeeds in corrupting the memory of a process, CFI prevents them from executing unauthorized instructions.

The adoption of CFI in V8 brings several benefits to the security landscape, significantly reducing the risk of successfully exploiting memory corruption vulnerabilities. These are usually the primary targets of attackers trying to gain control of a system.

By applying integrity checks to both forward and reverse control flow transfers, CFI decreases the possibility of attackers manipulating program execution to execute malicious code.

### 6. A Faster HTML Parser and DOM Allocation

In the pursuit of optimizing web performance, recent V8 updates have introduced significant improvements to both HTML parsing and DOM allocation.

A significant portion of time in a performance benchmark is spent parsing HTML.

Even though it's not a direct enhancement to V8, the team decided to apply their expertise in performance optimization to add a faster HTML parser to [Blink](https://www.chromium.org/blink/).

If you aren't familiar with it, Blink is the rendering engine used by Chromium and is based on the [WebCore](https://webkit.org/blog/114/webcore-rendering-i-the-basics/) component of WebKit.

These changes resulted in a notable 3.4% increase in the Speedometer scores.

Other optimizations have been applied to DOM memory allocation strategies within [Oilpan](https://chromium.googlesource.com/v8/v8/+/main/include/cppgc/README.md) — the V8 allocator for DOM objects.

By introducing a page pool mechanism and supporting compressed and uncompressed pointers, kernel round-trip costs have been greatly reduced.

Moreover, by avoiding compression for high-traffic fields, allocation workloads have become 3x faster.

These updates have led to significant improvements in DOM-heavy benchmarks, providing a smoother and more responsive browsing experience.

### 7. New WebAssembly Features

Just as with JavaScript, new features are continually added to Wasm. The main recent updates have been:

- Support for [`multi-memory`](https://github.com/WebAssembly/multi-memory) to deal with multiple memories in Wasm.
- Support for [`tail-calls`](https://github.com/WebAssembly/tail-call) to perform [tail-call optimizations](https://v8.dev/blog/wasm-tail-call).
- Support for [relaxed SIMD](https://github.com/WebAssembly/relaxed-simd) operation to unleash next-level performance.
- A completed implementation of [`memory64`](https://github.com/WebAssembly/memory64) for memory-hungry applications.

### 8. Memory Handling Optimizations Through Compile-Time Constant Addresses

Finally, V8 recently introduced a revolutionary improvement in memory management. This new feature is called [static roots](https://v8.dev/blog/static-roots) and aims to optimize the way basic JavaScript objects — such as `undefined` and `true` — are managed in memory. By assigning fixed memory addresses to these objects at compile time, V8 eliminates the need to look up addresses at runtime for a significant performance boost.

Thanks to static roots, access to commonly used objects becomes lightning fast. That's because V8 can now accurately predict their memory addresses at compile time. Not only does this optimization speed up code execution, but it also improves the performance of built-in C++ functions.

## What Do These V8 Engine Updates Bring to the Table?

Most of the recent V8 updates aim for the same results: to improve performance and security.

[As mentioned on the official V8 site](https://v8.dev/blog/holiday-season-2023), its performance improvements over a single year have been impressive, with an overall growth of 14% on JetStream and an astounding 34% on Speedometer.

This means that V8 is faster and more secure than ever. The possibility of running Python and Java on the web thanks to WasmGC is clearly huge. We will see how the web developer community reacts to this great news!

## Wrapping Up

In this blog post, we took a look at what V8 is and dug into the recent updates made to the popular JavaScript engine.

You now know:

- The top 8 recent V8 updates, including the new compilers available
- Why V8 is faster and more secure than ever

Thanks for reading!

**P.S. If you liked this post, [subscribe to our JavaScript Sorcery list](https://blog.appsignal.com/javascript-sorcery) for a monthly deep dive into more magical JavaScript tips and tricks.**

**P.P.S. If you need an APM for your Node.js app, go and [check out the AppSignal APM for Node.js](https://www.appsignal.com/nodejs).**