-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better WebAssembly integration #1325
Comments
I'd argue against mutations in the bundling process. Toolchains like The biggest problem with bundling WebAssembly modules is the asynchronous nature of their compilation when they are inlined as base64 and exceed 4KB. It could be solved by restricting the flexibility of how those modules are loaded, reducing the complexity of building such an integration. Given that you're working on the WebAssembly integration in Webpack, how did you approach it? And what did you settle on? |
Yes, the less we mutate the module the less can go wrong, but it was required in Webpack to fit into the ESM module system.
It's tight to Rust, I don't expect using it for bundling any time soon.
That's wrong, compilation can happen synchronously, even if not recommended (ok for service workers).
Inlining modules is not recommended because modules tends to be big.
Some engines have added a limitation for synchronous compilation. That's not an issue if we use |
Spawning a Worker to execute something synchronously isn't exactly synchronous. instantiateStreaming is also asynchronous because it's returning a Promise. (For Node.js specifically --) Parcel currently inlines If you're using Finally, if you need to mutate a WebAssembly module in order to fit a specific loader, and make that mutation default for the WebAssembly file type, then it would be better not to have it at all. Instead, this should be built as an extension for parcel that handles this specific use-case for users who choose to opt-in to it. |
According to
|
That's precisely not what I highlighted.
becomes
because Parcel generally inlines |
jfyi, this looks interesting: https://github.com/koute/parcel-plugin-cargo-web |
Is that possible to getting webassembly embbed as a string literal, not reading from filesystem? or fetch from remote URI. |
Note, I've been working on the WebAssembly/ESM integration standard, and I'd like to bring alignment between Parcel and the future built-in browser behavior. You can find the proposal at https://github.com/WebAssembly/esm-integration/blob/master/proposals/esm-integration/README.md . I'm not sure if this is the same as Parcel semantics or something different. Any feedback you have would be welcome. |
@lygstate You can use data URLs to embed WebAssembly as a string literal in the module specifier (but you might hit size limits). You can use CORS to fetch modules cross origin. |
@littledan I know this idea, but need parcel have a option support it |
I think we'd like to move forward with better WASM integration in Parcel 2. If someone would like to write up an RFC for what we'd need to do exactly and own this feature, that would be much appreciated! |
I would need to take a look at Parcel generated code, because we might need to rewrite the Wasm module a bit or add restrictions. For context, when instantiating a Wasm module, the imported JavaScript values are copied/snapshoted, as opposed to take their references. Similar to JavaScript Modules, if you rely on a linking phase and try to instantiate the module that won't work (what webpack does). Rollup on the other hand will inline/hoist the dependecies before the instantions which just works. |
Given that I don't have a project to work on aside from my own, I'm willing to give it a try. I'll start by implementing a naive approach to see where the issues lie and then come back with an RFC. |
I think the most flexible and least non-standard integration would be something like
|
No transformers found for add.wasm. |
It seems that the current WebAssembly integration imposes some restriction: #647.
💬 RFC
In order to provide the best integration we want wasm to be part of the ES module graph, and treated as any other ES module. It has some issues at the moment, you can find more details here https://github.com/WebAssembly/esm-integration (that we can avoid with some transformations).
Parcel don't necessarily need to expose the
importObject
since it can be automatically wired for the user.I propose you to use https://github.com/xtuc/webassemblyjs (disclaimer: i'm the author) to decode the wasm and apply transformations if needed (remove the start func, runtime, optimization etc).
🔦 Context
I'm currently working on the WebAssembly integration in Webpack.
💻 Examples
wasm decoding and introspection: https://github.com/webpack/webpack/blob/master/lib/wasm/WebAssemblyParser.js
transformation example: https://github.com/webpack/webpack/blob/master/lib/wasm/WebAssemblyGenerator.js
The text was updated successfully, but these errors were encountered: