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

Persistent filesystem storage in the webR REPL #56

Open
georgestagg opened this issue Aug 26, 2022 · 3 comments
Open

Persistent filesystem storage in the webR REPL #56

georgestagg opened this issue Aug 26, 2022 · 3 comments
Labels
feature New feature or request

Comments

@georgestagg
Copy link
Member

georgestagg commented Aug 26, 2022

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
Copy link
Member Author

georgestagg commented Jan 16, 2023

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,

  • localStorage and sessionStorage are unavailable in web workers, where we perform our R computation.
  • "OPFS" looks promising, but at the time of writing is only available in bleeding-edge Chromium browsers.
  • Emscripten's new "wasmFS" also looks promising but is currently Work in Progress.
  • The IndexedDB API (used by Emscripten's IDBFS driver) is asynchronous only. Since we block in the worker thread we're not able to use this API.
  • Service workers can be (ab)used to persist data, but only a single service worker can be active on the page at a time.

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
Copy link

gregvolny commented Jul 28, 2023

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

@georgestagg georgestagg added the feature New feature or request label Nov 1, 2023
@aehlke
Copy link

aehlke commented Nov 8, 2023

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.

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

No branches or pull requests

3 participants