Stream: jco

Topic: instance flags are generating a WebAssembly.Global?


view this post on Zulip Benjamin Bouvier (Nov 23 2023 at 16:56):

Hi! I'm trying to use jco to run a wasm module transpiled to JavaScript in a JS environment that has no access whatsoever to the WebAssembly global object (independent JSC runtime running on iOS). However, the transpiler is unconditionally generating one instanceFlags wasm global per runtime component instance, and in my toy example it does seem entirely unused. A bit more context: my use case involves only leaf components (aka no dependencies between components), which are plugin instances in a plugin system.

view this post on Zulip Benjamin Bouvier (Nov 23 2023 at 17:03):

I've tried to read a bit about the component model, and I've followed the breadcrumbs. It's unclear to me what these instance flags are; wasmtime tells me they're used to know if one may enter/leave a function (adapter function or the wasm-core function called by this adapter? I'm not sure), and also to indicate whether an adapter requires a post return or not.

My understanding is that adapters are only required whenever we have multiple components calling each other, and they required adapted arguments when calling each other. It's not the case in my toy example, as shown by the absence of uses of this instanceFlags0 in the rest of my code.

Instance flags support came up recently with the composed.wasm component in https://github.com/macovedj/composition/tree/main. Multi memories still seems to be the main todo to focus on, but instan...
Chatted with @alexcrichton a bit about #109 and he helped me put this together.

view this post on Zulip Benjamin Bouvier (Nov 23 2023 at 17:04):

So finally, my questions:

view this post on Zulip Benjamin Bouvier (Nov 23 2023 at 17:04):

(hope my understanding isn't too bad — I've only looked at all this t code today :smile:)

view this post on Zulip Guy Bedford (Nov 23 2023 at 19:12):

We generate instance flags even when they aren't explicitly used yes, that's more a case of missing dead code elimination I think (we do something similar for resource tables). Treating the instance flags as JS variables instead of Wasm ones might be possible, if we move all the checks of them into JS as well. It might require some adapting to setup trampolines to replace the globals with JS function calls if there are still places that expect to check them explicitly though.

@Alex Crichton wondering if you have any thoughts on if this would be possible in the model.

view this post on Zulip Benjamin Bouvier (Nov 24 2023 at 12:05):

Thanks! I've opened a small PR to lazily generate the instanceFlags variables, as a first step; let's see how it behaves (npm test passed on my machine at least :fingers_crossed:).

This lazily generates the instanceFlags, instead of emitting them all at once. The rationale is that if they're not required (e.g. in use cases involving only leaf components, if I understand corre...

Last updated: Oct 23 2024 at 20:03 UTC