Skip to content

How many times does WebAssembly.instantiate() need to be called?  #12757

Description

@nepx

Hi,

I'm trying to compile a number of command-line applications to WebAssembly via Emscripten, but along the way I realized that synchronous invocation of these commands is a must. After some inspection, I've come to realize that the main drawback is using WebAssembly.instantiate, an async/Promise function.

Right now, I pre-download a module using XHR and pass it through WebAssembly.compile, then passing that compiled module to WebAssembly.instantiate every time this command-line app needs to be run. Unfortunately, both aren't synchronous.

To illustrate, if I wanted to call ls three times in a row, I'd call the following functions:

execSync("ls");
execSync("ls");
execSync("ls");

The problem is that each time ls is run, it needs to be instantiated again (WebAssembly.instantiate) to give it a clean state, which breaks the synchronous nature of this code (I don't like this either, but it is what it is). Is there a way that I can instantiate it just once and reuse that for all subsequent invocations? Are there any hidden "gotchas," like dirty memory that needs to be cleared or WASM globals that need to be set to 0?

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions