Our great sponsors
- InfluxDB - Access the most powerful time series database as a service
- ONLYOFFICE ONLYOFFICE Docs — document collaboration in your environment
- SonarQube - Static code analysis for 29 languages.
- CodiumAI - TestGPT | Generating meaningful tests for busy devs
-
Hey HN, one of the creators here! I made it at Cruise because it was super painful to develop https://webviz.io with manual memory management (lots of ArrayBuffers), WebWorkers, etc. I thought that there must be a better way.
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?
-
I've been using a similar stack (C++ and WASM) to build some simple applications and I enjoy it very much. For the UI components I use Dear ImGui [0] as I am very familiar with it and it allows me to implement GUIs very fast. The biggest convenience is that you can run the same code both as a native application and as a web app. The biggest drawback is you usually get 100% CPU usage when there is an active animation in the WebGL canvas because you need to redraw everything (similar to the OP's example).
If you are interested, checkout my Github template repo [1] - it contains a few examples:
-
InfluxDB
Access the most powerful time series database as a service. Ingest, store, & analyze all types of time series data in a fully-managed, purpose-built database. Keep data forever with low-cost storage and superior data compression.
-
I've been using a similar stack (C++ and WASM) to build some simple applications and I enjoy it very much. For the UI components I use Dear ImGui [0] as I am very familiar with it and it allows me to implement GUIs very fast. The biggest convenience is that you can run the same code both as a native application and as a web app. The biggest drawback is you usually get 100% CPU usage when there is an active animation in the WebGL canvas because you need to redraw everything (similar to the OP's example).
If you are interested, checkout my Github template repo [1] - it contains a few examples:
-
Great work. Do you have any tips for debugging? I use the same combo for Glicol music programming language:
You can check it if you are interested.
-
I always encourage users to use vite, and it is quite easy for the dev server.
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...
-
ringbuf.js
Wait-free thread-safe single-consumer single-producer ring buffer using SharedArrayBuffer
I always encourage users to use vite, and it is quite easy for the dev server.
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...
-
Overhead of calling into JS from Wasm is very low; DOM calls are no problem since the DOM call itself is much slower than the overhead of switching from Wasm to JS. See e.g. this article from ~4 years ago: https://hacks.mozilla.org/2018/10/calls-between-javascript-a...
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!)
-
ONLYOFFICE
ONLYOFFICE Docs — document collaboration in your environment. Powerful document editing and collaboration in your app or environment. Ultimate security, API and 30+ ready connectors, SaaS or on-premises
-
zaplib
⚡ Zaplib is an open-source library for speeding up web applications using Rust and WebAssembly.
We used approach #1: https://github.com/Zaplib/zaplib/blob/7976d39775dd1642f20d8b...
I might write a blog post about this, since it's pretty fun / tricky stuff!
-
Nice project, although pretty opinionated. But I guess you have to do that when targeting the crazy browser environment with all its weird quirks (at least for non-web devs)..
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
-
Yes, I also went with the 1st one.
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?
Related posts
- You can specify lints with `[lints]` table in Cargo.toml on today's nightly!
- Detect when a webpage built with Yew is refreshed and store that value
- Just completely failed my first leetcode interview
- html! macro from yew web framework for wasm rust has embedded html code which is being highlighted incorrectly. I tried playing around with the tree sitter playground but i couldn't figure it out with my noob skills. how would you go about fixing this?
- Microsoft Loop with no dog food