Stream: git-wasmtime

Topic: wasmtime / issue #11159 DRC collector: use a better free ...


view this post on Zulip Wasmtime GitHub notifications bot (Jun 30 2025 at 18:49):

fitzgen opened issue #11159:

We use a very simple, first-fit free list for allocation in the DRC collector right now:

https://github.com/bytecodealliance/wasmtime/blob/57ba95e92eff1d02f6b05ab86b9e81b35bd69d28/crates/wasmtime/src/runtime/vm/gc/enabled/free_list.rs#L5

We should use something better, that has size classes and good hueristics and all that.

But also, we would ideally not write and maintain what is essentially our own malloc implementation ourselves, since getting all the details right and tuning them correctly for a variety of workloads is a lot of effort. The problem is that our malloc is outside the memory space that it is divvying up and parceling out: it is not inside the GC heap using and returning pointers within the GC heap, it is in the VM on the outside and is returning indices into the sandboxed region that makes up the GC heap, rather than pointers.

But... why not just compile dlmalloc (or something) to Wasm, have dlmalloc use the GC heap as its linear memory, and make GC allocations call dlmalloc's allocation and deallocation routines? That would give us a battle-hardened allocator that is most certainly faster than our free list pretty much For Free and with trivial long-term maintenance burden. Compiling dlmalloc to Wasm, with the right flags and exported symbols, results in a ~5-6 KiB binary that doesn't use any Wasm globals or funcref tables and uses only ~500 bytes of static data. It seems very doable.

This will rely on a lot of the same kind of infrastructure we want to have for compile-time builtins.

Random kinks to work out:

view this post on Zulip Wasmtime GitHub notifications bot (Jun 30 2025 at 18:49):

fitzgen added the performance label to Issue #11159.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 30 2025 at 18:49):

fitzgen added the wasm-proposal:gc label to Issue #11159.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 30 2025 at 19:49):

alexcrichton commented on issue #11159:

This will rely on a lot of the same kind of infrastructure we want to have for https://github.com/bytecodealliance/rfcs/pull/43.

I was thinking about this issue over the weekend I'm actually no longer certain that this is true. I believe that this can be implemented entirely independently of host builtins via a scheme such as:

Basically I don't think that any new trampolines are necessary, nor editing the compilation of any module. I think we could get away with this entirely with a Module stored in each GC implementation. Over time I think implementations like the current gc-or-maybe-grow logic would go entirely in GcHeap implementations to allow customizing that per-GC as necessary.


Last updated: Dec 06 2025 at 06:05 UTC