Recent Posts
Archives

Posts Tagged ‘WebAssembly’

PostHeaderIcon [OxidizeConf2024] The Fullest Stack by Anatol Ulrich

Embracing Rust’s Cross-Platform Versatility

Rust’s ability to operate seamlessly across diverse platforms—from embedded devices to web applications—positions it as a uniquely versatile language for full-stack development. At OxidizeConf2024, Anatol Ulrich, a freelance developer with extensive experience in web, mobile, and embedded systems, presented a compelling vision of the “fullest stack” built entirely in Rust. Anatol’s talk demonstrated how Rust’s “write once, compile anywhere” philosophy enables low-friction, vertically integrated projects, spanning embedded devices, cloud services, and web or native clients.

Anatol showcased a project integrating a fleet of embedded devices with a cloud backend and a web-based UI, all written in Rust. Using the postcard crate for serialization and remote procedure calls (RPC), he achieved seamless communication between an STM32 microcontroller and a browser via Web USB. This setup allowed real-time data exchange, demonstrating Rust’s ability to unify disparate platforms. Anatol’s approach leverages Rust’s type safety and zero-cost abstractions, ensuring robust performance across the stack while minimizing development complexity.

Streamlining Development with Open-Source Tools

A key aspect of Anatol’s presentation was the use of open-source Rust crates to streamline development. The dioxus crate enabled cross-platform UI development, supporting both web and native clients with a single codebase. For embedded communication, Anatol employed postcard for efficient serialization, agnostic to the underlying transport layer—whether Web USB, Web Serial, or MQTT. This flexibility allowed him to focus on application logic rather than platform-specific details, reducing friction in multi-platform projects.

Anatol also introduced a crate for auto-generating UIs based on type introspection, simplifying the creation of user interfaces for complex data structures. By sprinkling minimal hints onto the code, developers can generate dynamic UIs, a feature particularly useful for rapid prototyping. Despite challenges like long compile times and WebAssembly debugging difficulties, Anatol’s open-source contributions, soon to be published, invite community collaboration to enhance Rust’s full-stack capabilities.

Future Directions and Community Collaboration

Anatol’s vision extends beyond his current project, aiming to inspire broader adoption of Rust in full-stack development. He highlighted areas for improvement, such as WebAssembly debugging and the orphan rule, which complicates crate composition. Tools like Servo, a Rust-based browser engine, could enhance Web USB support, further bridging embedded and web ecosystems. Anatol’s call for contributors underscores the community-driven nature of Rust, encouraging developers to collaborate on platforms like GitHub and Discord to address these challenges.

The talk also touched on advanced techniques, such as dynamic type handling, which Anatol found surprisingly manageable compared to macro-heavy alternatives. By sharing his experiences and open-source tools, Anatol fosters a collaborative environment where Rust’s ecosystem can evolve to support increasingly complex applications. His work exemplifies Rust’s potential to deliver cohesive, high-performance solutions across the entire technology stack.

Links:

PostHeaderIcon [OxidizeConf2024] Unlocking the Potential of Reusable Code with WebAssembly

Reusing Rust Code in Web Applications

WebAssembly (WASM) has emerged as a transformative technology for reusing backend code in web applications, offering portability and performance across platforms. At OxidizeConf2024, Georg Semmler and Jonas Klein from Giga Infosystems presented a compelling case study on leveraging Rust and WebAssembly to enhance a geological subsurface modeling system. Their project, developed for a German federal agency, involved reusing computationally intensive Rust code for generating virtual boreholes in both backend systems and a 3D web viewer, showcasing WebAssembly’s potential to bridge backend and frontend development.

The GST system, comprising a Rust-based backend, a TypeScript-based web application, and a desktop client, manages large geological models with millions of triangles. Georg and Jonas explained how the virtual borehole feature, which calculates intersections between a cylindrical probe and subsurface layers, was initially implemented in Rust for the backend. By compiling this code to WebAssembly, they enabled the same functionality in the web viewer, allowing users to validate models against real-world data in real time, a critical requirement for geological analysis.

Implementing WebAssembly Workflows

The implementation process involved several key steps, which Georg detailed with clarity. The team used the wasm32 target to compile Rust code into WebAssembly binaries, leveraging Rust’s robust tooling, including Cargo and wasm-bindgen. This library facilitated seamless integration with JavaScript, enabling type-safe communication between the Rust code and the web application. To avoid blocking the main thread, the team employed web workers and Comlink, a library that simplifies worker communication, alongside shared array buffers to minimize data copying.

Performance comparisons underscored WebAssembly’s advantages. For a small model with 300,000 triangles, the Rust-WebAssembly implementation computed intersections in 7 milliseconds, compared to 100 milliseconds for an unoptimized TypeScript version. For larger models, the performance gap widened, with WebAssembly significantly outperforming TypeScript due to its native execution speed. However, Jonas noted challenges, such as WebAssembly’s 2GB memory limit, which required careful optimization of data structures to handle large geometries.

Real-World Impact and Future Directions

The adoption of WebAssembly in the GST system has profound implications for geological applications, particularly in public communication and geothermal energy exploration. Jonas highlighted use cases like visualizing radioactive waste disposal sites and assessing subsurface potential, which benefit from the system’s ability to handle complex 3D models. The team’s success in reusing Rust code across platforms demonstrates WebAssembly’s potential to streamline development, reduce duplication, and enhance performance.

Looking forward, Georg and Jonas plan to optimize memory usage further and explore additional WebAssembly use cases, such as integrating game logic for interactive visualizations. Their work underscores the importance of community collaboration, with contributions to open-source WebAssembly tools enhancing the ecosystem. By sharing their approach, they inspire developers to leverage Rust and WebAssembly for efficient, reusable code in data-intensive applications.

Links: