Shobhit Sharma
Posted on:November 6, 2023 at 05:00 AM

WASM GC Ports

I recently delved into the fascinating world of WebAssembly (WASM) Garbage Collection (GC) after stumbling upon this enlightening blog. I’ll try to provide an overview of what WASM GC is, its significance, and how it’s changing the landscape of web development.

What is Garbage Collection?

GC, short for Garbage Collection, is a memory management technique used by programming languages to automatically reclaim memory that is no longer in use. It’s like having a virtual janitor who tidies up memory by identifying and disposing of unneeded objects.

Why is GC Needed?

GC’s roots trace back to Lisp in the 1950s, aimed at simplifying memory management. Over the years, it became a crucial feature in various languages, including Java, Python, and JavaScript. GC empowers developers to focus on coding instead of memory management and mitigates the risk of memory leaks. Remarkably, WebAssembly did not natively support GC until recently, which meant developers had to manually manage memory—an error-prone and tedious task. Think calling malloc and free in C, or new and delete in C++, at least Rust has RAII.

How have we been using Python in WASM then?

Python has been used in WASM for a while now. However, to accomplish that we need something like Pyodide for Python or Blazor for C#. These projects involve compiling the language’s runtime into WebAssembly, making it interact seamlessly with WasmMVP’s features like linear memory, tables, and functions.

What is the WASM GC proposal?

The WASM GC proposal, often referred to as “WasmGC,” brings a revolutionary change by enabling the definition of struct and array types, allowing the creation, manipulation, and management of these objects. What sets it apart is that these objects are managed by the WebAssembly VM’s internal GC implementation, in contrast to the traditional approach used in the past.

If the traditional porting approach is how one ports a language to an architecture, then the WasmGC approach is very similar to how one ports a language to a VM.

Summary

WasmGC introduces a promising approach to implement GC-capable languages in WebAssembly. While traditional porting still has its place, WasmGC ports offer unique benefits. They can be more compact than traditional ports, even outperforming WasmMVP programs written in languages like C, C++, or Rust. Moreover, they integrate more seamlessly with the web, enhancing matters such as cycle collection, memory use, developer tooling, and more. WasmGC’s optimization capabilities provide significant speed advantages and encourage the sharing of toolchain efforts across various languages.

In essence, WebAssembly Garbage Collection is a game-changer, simplifying memory management and expanding the possibilities of what we can achieve on the web.