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.
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.
So finally, my questions:
instanceFlags
variables if/when they're required?(hope my understanding isn't too bad — I've only looked at all this t code today :smile:)
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.
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:).
Last updated: Nov 22 2024 at 17:03 UTC