Skip to content
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

async vs synchronous component function calls #691

Open
superchris opened this issue Dec 26, 2024 · 2 comments
Open

async vs synchronous component function calls #691

superchris opened this issue Dec 26, 2024 · 2 comments

Comments

@superchris
Copy link
Collaborator

I wanted to start this issue to hash out the design of how component function calls should work. Currently Wasmex.Components.call_function executes function calls and returns results synchronously, vs Wasmex.call_function for core wasm (non-component) modules is always async and returns results by sending a message to the calling process. I'd love to have component function calls remain synchronous where possible, but in the case of components which have imports this becomes no longer possible. The options in my mind are:

  1. Make call_function async and create an exec_function which returns immediately. Would also need a way in the use Component macro to specify whether the generated wrapper functions should be sync or async.
  2. Make component function calls always async with no option for sync
  3. ???

I'm leaning towards 1. It's pretty nice to be able to directly invoke a function and get a result where possible, but alas I don't think this will be possible when functions are imported (ie calling back into elixir from a wasm component).

Thoughts (@tessi, @RoyalIcing, etc)?

@RoyalIcing
Copy link
Collaborator

Is the desire for synchronous over asynchronous because of difference in behaviour or performance?

@tessi
Copy link
Owner

tessi commented Dec 27, 2024

I'd love to have component function calls remain synchronous where possible

why? 🙃

but in the case of components which have imports this becomes no longer possible

true! And because of that my feeling is to be consistent (with regular Wasm and import-components) and always use async calls. IMO consistency is good for us - wasmex is already quite a complex project, let's keep the number of different implementations of a single functionality (-> function call) small.

Outside of consistency and less overall API surface we have to maintain, I think this plays nicely with the BEAM too. Normally, NIF calls shall return fast (or it's a "dirty NIF" - see: https://www.erlang.org/docs/25/man/erl_nif and ctrl+F for "dirty"). I'd love to avoid that.

So IMO, lets go route 2

Make component function calls always async with no option for sync

Caveat: We didn't benchmark wasmex yet (a thing I want to do - especially if my ElixirConfEU talk was accepted). MAYBE direct (non-async) calls are much faster?! if so, we MIGHT want to reconsider :) But even if, it has the drawback that the user needs to know implementation details like whether a function calls into an import or not. This alone makes it quite a footgun in my opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants