wasmer-js icon indicating copy to clipboard operation
wasmer-js copied to clipboard

Saving to IndexedDB instead of memfs

Open andersson09 opened this issue 3 years ago • 4 comments

Hello

Is it possible to have a configuration that allows the executing WASI/WASM packages to store to a persistent storage provider such as IndexedDB rather than memfs?

Also my other question is slightly unrelated but can wasm-terminal also run WASM or only WASI packages?

Thanks!

andersson09 avatar Oct 31 '21 12:10 andersson09

Hi! I have recently implemented some logic in my own code (not part of wasmer) that synchronizes a memdb with an IndexedDB. https://github.com/corwin-of-amber/Web.Author/blob/master/src/net/local.ts

It takes advantage of fs.watch. Unfortunately, memfs does not implement recursive watch... so I needed to wrap the memfs Volume with my own SubdirectoryVolume: https://github.com/corwin-of-amber/Web.Author/blob/master/src/infra/volume.ts#L59

Feel free to copy my source 😄

I am afraid the (brilliant) TypeScript implementation of the wasmer runtime has been abandoned for now, so I do not much expect it to progress. But if you happen to add some functionality I am sure they will appreciate PRs.

corwin-of-amber avatar Oct 31 '21 15:10 corwin-of-amber

Thanks will take a look. When writing to memfs does it individually store each file to the db and remove the file from memfs to clear space or does it just place whatever is inside memfs to indexeddb similarly to emscripten idbfs? My only concern would be how this deals with reading large file streams from db without loading anything to memory.

andersson09 avatar Nov 02 '21 20:11 andersson09

Ah, it's not very smart tbh. It makes a clone of whatever is in the memfs, which it stores in the IndexedDB. Then when you reload the page it reads the entire DB back to memory. Indeed for large files this would be infeasible.

corwin-of-amber avatar Nov 02 '21 21:11 corwin-of-amber

Ah, it's not very smart tbh. It makes a clone of whatever is in the memfs, which it stores in the IndexedDB. Then when you reload the page it reads the entire DB back to memory. Indeed for large files this would be infeasible.

Thanks for the quick reply. That's useful to know.

andersson09 avatar Nov 02 '21 21:11 andersson09