-
Notifications
You must be signed in to change notification settings - Fork 12
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
Why do HTTP plugins have to be run in a web worker? #103
Comments
The asynchronous nature of JS ends up being the issue! At the time of writing, Wasm runs on the same thread that it's invoked on and expects host functions to complete synchronously with respect to that thread. So if you were to call So, what we do is push the guest onto a background Worker thread, which can block until async host functions executed on the main thread are resolved, essentially suspending the execution of the Wasm at the host function call site until the HTTP request resolves. Luckily, there's an effort to standardize this That said, there are other reasons to execute sync, compute-heavy Wasm on background threads– (as you know!) contention on the main thread can seriously affect the performance of most JS server platforms. So we'll continue to support Worker threads into the future. (But the good news is that JSPI will make supporting the worker threads even simpler, too, in that we won't have to use our own locks for copying data up and down.) Footnotes
|
Sounds like I'm on the bleeding edge. Thank you for the detailed answer! |
My extism plugin is coming along very nicely. I'm pretty confident at this point that it will be able to do everything I need.
One issue I've run into is that the requirement to use a web worker for HTTP plugins adds quite a bit of complexity. Given that JS is async and should be able to handle everything on a single thread, I'm wondering why this is necessary?
The text was updated successfully, but these errors were encountered: