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

Tracking: WASM Bindings (Group Chat Prod - Web) #557

Open
1 of 30 tasks
nplasterer opened this issue Mar 19, 2024 · 6 comments
Open
1 of 30 tasks

Tracking: WASM Bindings (Group Chat Prod - Web) #557

nplasterer opened this issue Mar 19, 2024 · 6 comments

Comments

@nplasterer
Copy link
Contributor

nplasterer commented Mar 19, 2024

@bwcDvorak
Copy link
Contributor

Github, your 'convert to item' did me dirty when it came to converting issue 564, formerly a task about making the WASM bindings with a reference to an external URL. Apologies @nplasterer - can you please edit the correct title back into that issue?

@nplasterer
Copy link
Contributor Author

nplasterer commented Mar 25, 2024

@bwcDvorak I think that item is just a header and doesn't need to be an issue. I restored it from the edit history. It was just linking out to the repo that will help with the bindings.

@bwcDvorak
Copy link
Contributor

TYVM!

@bwcDvorak bwcDvorak changed the title Tracking: Group Chat - Web Tracking: WASM Bindings (Group Chat Prod - Web) Mar 26, 2024
@nplasterer nplasterer unpinned this issue May 31, 2024
@neekolas
Copy link
Contributor

neekolas commented Jun 25, 2024

We've talked a lot about WASM bindings in terms of "make everything happen in Rust". The two sticking points are disk access (SQLite) and networking (GRPC Gateway or GRPC Web). To access the device APIs to do this in Rust, we'd need to use WASI. WASI is very bleeding edge, and making it work in a full-featured app that supports things like async and streaming, is going to be a big lift.

We haven't spent a lot of time discussing the other alternative to make libxmtp work on the web: doing all this work in JS. WASM (without WASI) supports calling into JS functions from Rust. We already have a trait for the API layer, where we could implement it in Javascript and write a JS -> Rust binding to expose an implementation of that trait (or use the pre-existing fetch API binding that already exists as part of web-sys) to write some of the business logic in Rust on top of the fetch API. We would then need to convert our storage layer into a trait, and likely refactor a bunch of our code that deals with things like transactions to support a generic storage interface that could be implemented in JS using IndexedDB.

Risks:

  • Support for streaming and passing callbacks back and forth between Rust and JS
  • Complicated refactor of our storage-related code to be more generic
  • Is IndexedDB able to do everything we currently do with SQLite. Some functions might need to be done in a hacky way.
  • Performance. This will be slower. How much slower? I don't know

I don't think we know enough yet for me to advocate for this solution. But it's a much clearer path than WASI and probably deserves a spike to derisk.

@insipx
Copy link
Contributor

insipx commented Jun 25, 2024

Wasm runtimes support Host Functions. This seems to be similar to this, where we would expose a rust trait that JS needs to implement and pass host functions into the generated WASM blob. These host functions would generally be write/read etc, whatever SQLite normally does in the rust code. Could be very close to the trait Cryspen made for OpenMLS. This would require a bit of work on the JS side, but it does circumvent the need for WASI, at least until its in a more stable state.

The downside here is we would need to convert all our sqlite insert/read code to a generic trait and implement it on the rust side too.

@neekolas
Copy link
Contributor

The fact that wasm_bindgen supports really complicated browser APIs in web-sys (it can do things like use WebGL) gives me hope that the host function support is pretty mature and full-featured.

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

No branches or pull requests

5 participants