Very curious to hear stories from other folks building intensive stuff in the browser. How are you dealing with performance issues in Javascript? Have you tried using Rust or C++ with WebAssembly for parts of your apps? How did you make 2d/3d rendering faster? Would you want to use something like Zaplib?
(You may have seen my blog yesterday about the subtleties about Wasm vs JS/TS: https://zaplib.com/docs/blog_ts++.html)
(I know there is some proposal that might allow WASM to interact with the DOM directly too, but I don't know how likely it will be merged.)
There are even some libraries that try to mimic React directly from Rust, such as https://yew.rs/ (though in my experience they can be a bit harder to use than Zaplib, since they require you to learn about traits, closures, etc, and tend to also run into borrow checker issues more often -- all of those are things we try to avoid having to learn in Zaplib!)
Using the obvious way, GL shaders.
The amount of time spent on the CPU side is mostly irrelevant, preparing buffers that can only be done from JS code anyway.
I can't really say much else about it, but it looks interesting.
ADD: not complaining about the down votes, but I wasn't kidding. I think it's malfunctioning in my browser in a literally dangerous way. I would record a video of it if it wasn't so annoying to upload. I'm guess nobody else sees this?
The audio runs in AudioWorklet thread while I guess for Zaplib it runs in Workers, right? Did you use SAB in Zaplib?
For me, one use case is to use Zaplib for visualising the audio. The built-in canvas and 2d drawing is really slow. Yet one concern is for the support on Safari. It really has a slow support for SAB. I have to switch to postMessage on Safari as a compromise.
For debugging we support full Rust source maps in the browser (using DWARF). :D (This is something that wasm-bindgen doesn't support, for example!) See https://zaplib.com/docs/developer_environment.html#chrome-de... for how to set it up.
Since we also support running the Rust code natively (even when doing rendering!) you can also use that and attach whatever native debugger you like. That same page also has info on how to set up native debugging with VSCode.
https://github.com/vitejs/vite/issues/3909
For deployment it's a different story then but for example netlify has a quite intuitive way to set headers for CORS:
https://github.com/padenot/ringbuf.js/blob/master/public/_he...
If you are interested, checkout my Github template repo [1] - it contains a few examples:
All in all the performance is great for highly interactive stuff that does some fair amount of client side data processing.
I notice that you also came to the conclusion that having all io async is not the way to go for rust.
How do you wrap the async js io apis so they can be used in sync rust? I have seen different approaches for this: 1. an additional service worker / thread and atomics. 2. rewrite the entire WASM in some sort of continuation passing style.
I might write a blog post about this, since it's pretty fun / tricky stuff!
Basically the main thread sends a command to an io executor thread, and then waits on the result, which is done using atomics under the hood.
See e.g. https://github.com/cloudpeers/radixdb/blob/sqlite/browser/sr...
Can't wait to play with zaplib. Can you also use it as just a standard library without the GUI part?
Somewhat related is a library I've been working on to generate an ffi between Rust and js code: https://github.com/cloudpeers/ffi-gen
Also I really like your universal_thread abstraction, hiding the whole web worker mess. I did a similar thing here: https://github.com/wngr/wasm-futures-executor
I can understand from an ease of use perspective to have the bridge in between but it wouldn’t be worth subjecting a codebase to commercial licensing IMO. It’s not a whole lot more work to use process calls instead there so it seems an odd choice to commercialize that aspect in particular.
> Zapium is the native, cross-platform Zaplib runtime. It converts Zaplib web apps to desktop apps, where the Rust code runs natively, not via WebAssembly.
> This is Zaplib's equivalent of Electron -- for an extra speed boost.
not certain if this should be the status quo for the longer term.
We also support building compiling to native though, and we've found that the typical difference between Wasm and native apps is about 2x (on most metrics).
iPhone XS on iOS 15.0.2
It's definitely bleeding-edge stuff; we should add some backwards compatibility for (slightly) older browsers though.