RC RANDOM CHAOS

Wasmtime 47 ships Wasm GC and exceptions on by default

· via Hacker News

Original source

GC and Exceptions in Wasmtime

Hacker News →

Wasmtime 47 turns on two long-awaited WebAssembly features by default: garbage collection and exceptions. Both proposals have now merged into the core WebAssembly spec, and their arrival in the runtime is the payoff from years of engineering. Together they make Wasm a far more practical compilation target for high-level languages. Wasm GC lets programs define their own struct and array types and hand lifetime management to the runtime, so languages built around objects and references no longer have to bundle their own collector into every .wasm binary. The exceptions proposal similarly replaces the awkward custom calling conventions toolchains used to signal thrown errors — which added binary bloat and slowed the normal return path — with native throw and try/catch constructs that impose zero overhead when nothing is thrown.

Wasmtime’s collector is a Cheney-style semi-space copying design: objects bump-allocate into an active space, and live ones are copied to a fresh space during collection, with no read or write barriers. Notably, the GC heap is built on top of Wasm’s existing linear memory, and object references are 32-bit indices rather than native pointers. That choice pays off on all three of Wasmtime’s core goals — safety (collector bugs can’t escape the sandbox into host memory), speed (guard-page bounds-check elision, integration with the pooling allocator’s ~5µs instantiation, and cache-friendlier 32-bit refs), and portability (the existing linear-memory implementation already handles per-platform special-casing, down to bare metal). The team hardened correctness by extending wasm-smith and adding two targeted fuzzers for object graphs and heap corruption.

The honest caveat: this collector is new and tuned for Wasmtime’s dominant production pattern — many small, short-lived instances that scale horizontally — rather than single long-lived processes, so throughput and latency won’t rival the decades-tuned collectors in V8 or SpiderMonkey yet. Next steps include GC-aware alias analysis for more aggressive load/store optimization, and integrating GC with the component model so garbage-collected languages become first-class citizens without dragging along unused linear memories.

Read the full article

Continue reading at Hacker News →

This is an AI-generated summary. Read the original for the full story.