Overview
This project was inspired by the work done at Figma, who periodically posts engineering blogs about the technology they use to power their design software on the web. It initially grabbed my interest as a lot of web technoollgies revolve around either a Javascript or Typescript graphics library like three.js to do their actual rendering.
Figma uses C++ and emscripten targeting webGL but more recently have done WebGPU. I finally had an excuse to try out Rust and WebGPU and tried to create some vector editing capabilities!
Architecture
I don't fully remember the details, but I think Figma mentioned they use a Javascript/Typescript front end library, like react for their UI implementations. I also did this and in doing so, there was a lot of glue code that had to be made during this process.
Rust will generate a .wasm binary that you have to include. The glue code will query this binary for it to do certain actions against the chrome backend.
Graphics Pipeline
If you want anything displayed in a browser, you had to enable the webgpu option in cargo assuming you are using wgpu library. At that point, my web development and Rust skills for that matter were not as developed as my C++ skills, so I struggled with some of the non trivial features.
The WebGPU interface is quite nice to work with though. It does not get into the complexity of a modern graphics api like Vulkan or DirectX12, but almost in between OpenGL and the modern complciated graphics API. It was still difficult I would say, but managable and the Rust docs do help a lot here.
Performance
I actually never got into a point where the performance of the Rust backend was immediately noticable. In Figma, you can have possibily hundreds of thousands of shapes where designers are zooming in and out of the canvas moving around a lot. Trying to get a consistent 60 frames per second could be a challenge, but this project never got as developed as I hope to initially.
Challenges
Rust compile times are nothing to really ignore when you are doing high-iteration experiences. I noticed that even in extremely trivial projects in Rust, the build times (depending on your cargo stack) can balloon out of control. For example, if you do not optimize anything and you are using the bevy library for creating games, the build times can reach upwards of 10 minutes. Even though the initial build is partially cached, there is still a significant amount of time you will to wait for the build.