Skip to content

API Concerns with Structured Clone for Wasm Modules #972

@flagxor

Description

@flagxor

Some have expressed concerns that structured clone for wasm modules is a bad choice of contact point into the web platform.
In particular, it has these drawbacks:

  • It encourages modules with the origin in which WebAssembly.compile was done, rather than the url of the bytes came from.
  • It encourages use of IndexedDB as an application managed compilation cache, rather than leveraging the existing caching mechanisms in the browser. Requiring middleware vendors to get the caching pattern right.
  • It encourages use of postMessage for module for cross-origin shared modules.

We have casually assumed that the current mechanism would soon be augmented by support for WebAssembly.compile of a ReaderStream (for instance from fetch), to allow streaming compilation.
We've also discussed the possibility of surfacing wasm modules as es6 modules.

Have we found the right contact point?
Alternatives exist such as:

  • Expand the Cache (service worker API) to support wasm compilation and explicit caching of wasm code, and knowing when it's actually compiled.
  • Ensure Foreign fetch allows the possibility of sharing a wasm module cross-origin.
  • Pass an URL instead of an ArrayBuffer to WebAssembly.compile. Using things like blob urls for dynamic cases.

We've already implicitly assumed we'll want to support more options.
Will any of those subsume the current interface to the point we'll want to deprecate it at some point?
Do we want to consider limiting the scope of structured cloning to plan for better future patterns?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions