Skip to content

Priority: JavaScript-integrated GC or primitives for implementing GC in WASM #733

Closed
@AndrewScheidecker

Description

@AndrewScheidecker

My primary concern with WebAssembly right now is not anything in the current spec, but rather that the design anticipates the addition of GC reference types. I think this is an unnecessary coupling of WebAssembly to existing JavaScript engines.

I can understand the motivation for adding GC references, and that the cost doesn't seem so bad to most of you who are implementing runtimes within existing JavaScript engines. But I'm sure you can see that if GC reference types are a de facto requirement, that limits the use of WebAssembly outside of browsers.

Even if it is added as an optional extension, a WebAssembly implementation without it will become pointless if Emscripten uses it. I already have problems running Emscripten compiled binaries in WAVM due to the coupling of its C runtime to its JavaScript harness. If that interface starts to use GC references, then I will need to add a garbage collector to my standalone WebAssembly VM.

I don't want to add a garbage collector to my WebAssembly VM, not because I don't want to write a garbage collector, but because I want to write a garbage collector within WebAssembly. I'm developing a programming language that will compile to WebAssembly, and for many reasons, I think a language-specific garbage collector will be more effective than a language-independent TypedObject collector, even within the limitations of the WebAssembly abstraction.

GC.md is entirely about exposing the JavaScript object model to WebAssembly programs, with no mention of exposing primitives to WebAssembly that allow efficient implementation of a garbage collector. This worries me as much as the risk that Emscripten(or other toolchains) will make GC references a required feature; I know that folks are aware of, and not opposed to, the desire to implement a GC within WebAssembly, but that's clearly not where resources are focused.

In my opinion that focus is misplaced. The web will benefit the most from new applications that are enabled by WebAssembly performance, not from making existing applications faster. I anticipate new applications using WebAssembly will want to work with their own DOM in linear memory, with some isolated code to replicate that into the browser DOM.

I think the strongest argument for a VM-level GC is that for languages whose data maps well to TypedObjects, a VM-level GC benefits from direct access to the hardware and OS. Perhaps this is a worthwhile optimization, but I think enabling a WebAssembly application to do its own GC should be the primary goal.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions