Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

WebAssembly support #32

Closed
skyne98 opened this issue Oct 11, 2018 · 12 comments
Closed

WebAssembly support #32

skyne98 opened this issue Oct 11, 2018 · 12 comments

Comments

@skyne98
Copy link

skyne98 commented Oct 11, 2018

Hey there! As far as I can see, ZboxFS has its ways of using the native FS and other services, therefore making me wonder if it can be successfully compiled to WASM and use as an in-memory secure file system. Are there any plans for it?

Thanks!

@burmecia
Copy link
Contributor

Yes, WebAssembly support is definitely possible and it is in the roadmap. That sounds very interesting for me as well as we can run a virtual file system in browser! But to do that we need greatly reduce the binary size first, currently it is too large.

@skyne98
Copy link
Author

skyne98 commented Oct 15, 2018

@burmecia, what is the binary size is not a problem for some projects? If you are choosing to write a web project with Rust now, you may be ready for big binary sizes. Is it possible to do it now, not considering the big binary sizes?

@vladimiry
Copy link

@burmecia WebAssembly can also be used at the backend/Node.js where the size of the dependency is less important than on the web.

@burmecia
Copy link
Contributor

@skyne98 , @vladimiry After LLVM 8.0 was released, zbox WebAssembly support is finally possible. The hardest part was to integrate libsodium wasm with zbox. libsodium used emscripten to compile to wasm, while zbox use rust wasm-bindgen. Those 2 parts were hard to linked together without handful hacks. But now libsodium can be directly compiled to wasm by LLVM, which made wasm-bindgen easier to link to zbox.

The binary size now is around 2.3 MB (700KB+ gzipped) with some optimization, which is not too crazy. But I'd say still has some rooms to improve.

I am doing some polishing work now, hopefully will release it soon.

@skyne98
Copy link
Author

skyne98 commented May 11, 2019

@burmecia, good news! I already played with libsodium and wasm myself, so I can confirm it works.

I think a small web demo using zbox for people to play with would be nice. Can spark interest in someone as well as explain basic concepts much better.

Also, have you tried passing a -Oz flag to LLVM directly?

@burmecia
Copy link
Contributor

@skyne98 , yes I tried -Oz flag, but -Os flag seems produce slightly smaller binary size. So I made it default flag for release build.

A small web demo sounds a good idea. IndexedDB as the underlying storage, zbox runs in wasm, javascript as frontend provides POSIX-like async API, then we have a private filesystem running in browser! I will definitely put this on my task list.

@skyne98
Copy link
Author

skyne98 commented May 11, 2019

Sounds like a plan 😉

@theduke
Copy link

theduke commented Jun 5, 2019

Is the the plan here to use localStorage as a backing storage layer for browser support? If yes that would be awesome

@skyne98
Copy link
Author

skyne98 commented Jun 5, 2019

I think @burmecia mentioned using IndexedDB as backing storage. This will allow persisting the state between sessions (in theory).

@theduke
Copy link

theduke commented Jun 5, 2019

The guarantees for IndexDB vs localStorage aren't really different, both are labeled as "temporary" and may be wiped out at any time. I do believe though that browsers are more forgiving with IndexDB both in terms of size restrictions and eviction.

There is a draft spec that allows requesting persistence that is not allowed to be wiped out arbitrarily.
https://storage.spec.whatwg.org/#persistence

I believe this is implemented in FF and Chrome.

@burmecia
Copy link
Contributor

burmecia commented Jun 5, 2019

The persistent web storage is fantastic but it is still experimental, some browsers even don't support it yet. For now, IndexedDB is used as local cache, it can persist between sessions but doesn't rely on it to provide durable storage.

@burmecia
Copy link
Contributor

The wasm binding prototype is finally on https://zbox.io/try. Feel free to create a test repo and run it in browser. For now, only Chrome and Firefox is supported, the other browsers may have issues. Please raise issue on this repo: https://github.com/zboxfs/zbox-browser, as the wasm binding is now moved out to it.

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

No branches or pull requests

4 participants