Skip to content

WasmFS: Async APIs #15964

Open
Open

Description

@tlively

In addition to the traditional POSIX APIs, some applications would benefit from having asynchronous file system APIs as well. Perhaps there could be default implementations that just call the synchronous version of the API and immediately call the user callback, the specific backends could specialize that default as appropriate.

Activity

  1. moved this to Todo in WasmFSon Jan 11, 2022
  2. added this to the WasmFS new features milestone on Jan 11, 2022
  3. medns commented on Sep 22, 2023

    @medns
    Contributor

    I need it so much! 🥇
    Using the asynchronous interface, can directly call the file system in web worker and main thread without blocking and unnecessary thread(sync thread) overhead.

  4. ifiddynine commented on May 29, 2024

    @ifiddynine
    Contributor

    Is this still planned? Our codebase uses POSIX async IO (aio) where available, but the web version currently needs a fallback using fopen (with directories mapped using wasmfs_create_directory and an opfs backend).

    Would be amazing to unblock native workers that request files (and later on write too, but that's not too important for us right now).

    P.S. I know that musl supports aio, but I assume this is stripped out of emscripten on purpose due to not being implemented? @sbc100 I see you've been updating it recently, do you know the procedure?

  5. sbc100 commented on May 29, 2024

    @sbc100
    Collaborator

    I imagine it would be a fair amount of work to implement aio. In particular aio_suspend would require something like ASYNCIFY in order to work.

  6. ifiddynine commented on May 29, 2024

    @ifiddynine
    Contributor

    Yup I can see that, luckily we don't use aio_suspend ourselves.

    Looking at the opfs implementation we could probably switch over to the native wasm_fs API later on instead of aio. From first glance _wasmfs_opfs_read_blob would be enough for us, blocker seems to be that we don't have access to the wasmfs worker thread / proxy context. Might give exposing some minimal read-only async API a go at some point.

  7. adamziel commented on Aug 2, 2024

    @adamziel

    This is a blocker for supporting large local sites and multiple PHP web workers in WordPress Playground.

    We support synchronizing data between MEMFS and a DirectoryHandle. However, lacking a pthreads build of WebAssembly limits what we can do with the filesystem. We don't have a good way of:

    • Synchronizing MEMFS between workers
    • Synchronizing concurrent writes to a local FileSystemFileHandle between workers
    • Stream-reading large files from a local FileSystemFileHandle without loading them into memory

    With an asynchronous filesystem, we could mount a FileSystemDirectoryHandle at, say, /wordpress, and directly interact either with OPFS or with the local filesystem.

    I was looking for a way to use OPFS mounts for a while, but couldn't find any resources. I also couldn't figure that out from the wasmfs_opfs.c link that often gets passed around as an example.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status
      Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions