r-wasm / webr

The statistical language R compiled to WebAssembly via Emscripten, for use in web browsers and Node.
https://docs.r-wasm.org/webr/latest/
Other
884 stars 69 forks source link

Persistent filesystem storage in the webR REPL #56

Open georgestagg opened 2 years ago

georgestagg commented 2 years ago

Perhaps by mounting an Emscripten IDBFS filesystem somewhere like /storage.

We will need to think about long term storage implications. Browser localStorage will work in the short term but could be cleared away at any moment.

georgestagg commented 1 year ago

Copying a comment here with an update on the current situation,

For webR in particular a persistent VFS is tricker than at first glance. We cannot immediately use solutions that work well for other WASM projects because we use a blocking worker thread to maintain our place in the stack while waiting for input for R. Due to this we cannot easily yield to the event loop in the worker thread[1].

From what I currently understand there are several options available, but each have their own drawbacks for us,

I think the future of persistent storage in webR is going to be based around synchronous OPFS or wasmFS API, once they are ready and supported by more browsers. In the meantime, solving this issue will probably involve significant new infrastructure based around passing messages to the main thread to persist data.

[1] Asyncify would allow us to yield, but it does not work well for us due to the way the R interpreter works and the large asyncify overhead induced.

gregvolny commented 1 year ago

@georgestagg , since this post, OPFS is widely supported in more browser. Wordpress playground already implemented it: https://github.com/WordPress/wordpress-playground/pull/548 Also, the new JSPI : https://v8.dev/blog/jspi can be an alternative for asyncify overhead issues. Best,

aehlke commented 1 year ago

It looks unclear whether Safari on Mac or iOS will get it anytime soon :/ They have it in no preview state and I see no plans for it. Unfortunately I think OPFS isn't a universal solution.