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 [DotJs2024] The Future of Serverless is WebAssembly

Envision a computing paradigm where applications ignite with the swiftness of a spark, unbound by the sluggish boot times of traditional servers, and orchestrated in a symphony of polyglot harmony. David Flanagan, a seasoned software engineer and educator with a storied tenure at Fermyon Technologies, unveiled this vision at dotJS 2024, championing WebAssembly (Wasm) as the linchpin for next-generation serverless architectures. Drawing from his deep immersion in cloud-native ecosystems—from Kubernetes orchestration to edge computing—Flanagan demystified how Wasm’s component model, fortified by WASI Preview 2, ushers in nanosecond-scale invocations, seamless interoperability, and unprecedented portability. This isn’t mere theory; it’s a blueprint for crafting resilient microservices that scale effortlessly across diverse runtimes.

Flanagan’s discourse pivoted on relatability, eschewing abstract metrics for visceral analogies. To grasp nanoseconds’ potency—where a single tick equates to a second in a thrashing Metallica riff like “Master of Puppets”—he likened Wasm’s cold-start latency to everyday marvels. Traditional JavaScript functions, mired in milliseconds, mirror a leisurely coffee brew at Starbucks; Wasm, conversely, evokes an espresso shot from a high-end machine, frothy and instantaneous. Benchmarks underscore this: Spin, Fermyon’s runtime, clocks in at 200 nanoseconds versus AWS Lambda’s 100-500 milliseconds, a gulf vast enough to render prior serverless pains obsolete. Yet, beyond velocity lies versatility—Wasm’s binary format, agnostic to origin languages, enables Rust, Go, Zig, or TypeScript modules to converse fluidly via standardized interfaces, dismantling silos that once plagued polyglot teams.

At the core lies the WIT (WebAssembly Interface Types) component model, a contractual scaffold ensuring type-safe handoffs. Flanagan illustrated with a Spin-powered API: a Rust greeter module yields to a TypeScript processor, each oblivious to the other’s internals yet synchronized via WIT-defined payloads. This modularity extends to stateful persistence—key-value stores mirroring Redis or SQLite datastores—without tethering to vendor lock-in. Cron scheduling, WebSocket subscriptions, even LLM inferences via Hugging Face models, integrate natively; a mere TOML tweak provisions MQTT feeds or GPU-accelerated prompts, all sandboxed for ironclad isolation. Flanagan’s live sketches revealed Spin’s developer bliss: CLI scaffolds in seconds, hot-reloading for iterative bliss, and Fermyon Cloud’s edge deployment scaling to zero cost.

This tapestry of traits—rapidity, portability, composability—positions Wasm as serverless’s salvation. Flanagan evoked Drupal’s Wasm incarnation: a full CMS, sans server, piping content through browser-native execution. For edge warriors, it’s liberation; for monoliths, a migration path sans rewrite. As toolchains mature—Wazero for Go, Wasmer for universal hosting—the ecosystem beckons builders to reimagine distributed systems, where functions aren’t fleeting but foundational.

Nanosecond Precision in Practice

Flanagan anchored abstractions in benchmarks, equating Wasm’s 200ns starts to life’s micro-moments—a blink’s brevity amplified across billions of requests. Spin’s plumbing abstracts complexities: TOML configs summon Redis proxies or SQLite veins, yielding KV/SQL APIs that ORMs like Drizzle embrace. This precision cascades to AI: one-liner prompts leverage remote GPUs, democratizing inference without infrastructural toil.

Polyglot Harmony and Extensibility

WIT’s rigor ensures Rust’s safety meshes with Go’s concurrency, TypeScript’s ergonomics—all via declarative interfaces. Spin’s extensibility invites custom components; 200 Rust lines birth integrations, from Wy modules to templated hooks. Flanagan heralded Fermyon Cloud’s provisioning: edge-global, zero-scale, GPU-ready— a canvas for audacious architectures where Wasm weaves the warp and weft.

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:

PostHeaderIcon [KotlinConf2023] KotlinConf’23 Keynote: The Future of Kotlin is Bright and Multiplatform

KotlinConf’23 kicked off with an energizing keynote, marking a much-anticipated return to an in-person format in Amsterdam. Hosted by Hadi Hariri of JetBrains, the session brought together key figures from both JetBrains and Google, including Roman Elizarov, Svetlana Isakova, Egor Tolstoy, and Grace Kloba (VP Engineering for Android Developer Experience at Google), to share exciting updates and future directions for the Kotlin language and its ecosystem. The conference also featured a global reach with KotlinConf Global events in 41 countries. The main announcements from the keynote are also available in a blog post on the Kotlin blog.

The keynote celebrated Kotlin’s impressive growth, with statistics highlighting its widespread adoption, particularly in Android development where it’s the most popular language, used in over 95% of the top 1000 Android apps. A major focus was the upcoming Kotlin 2.0, centered around the new K2 compiler, which promises significant performance improvements, stability, and a foundation for future language evolution. The K2 compiler is nearing completion and is set to be released as Kotlin 2.0. The IntelliJ IDEA plugin will also adopt the K2 frontend, aligning with IntelliJ releases.

The Evolution of Kotlin: K2 Compiler and Language Features

The K2 compiler was a central theme of the keynote, marking a major milestone for Kotlin. This new compiler front-end, which also powers the IDE, is designed to be faster, more stable, and enable the development of new language features and tooling capabilities more rapidly. Kotlin 2.0, built on K2, is expected to bring these benefits to all Kotlin developers, enhancing both compiler performance and IDE responsiveness.

Looking beyond Kotlin 2.0, the speakers provided a glimpse into potential future language features that are under consideration. These included:
* Static Extensions: Allowing extension functions to be resolved statically, potentially improving performance and clarity.
* Collection Literals: Introducing a more concise syntax for creating collections, like using square brackets for lists, with efficient implementations.
* Name-Based Destructuring: Offering a more flexible way to destructure objects based on property names rather than just position.
* Context Receivers: A powerful feature for providing contextual information to functions in a more implicit and structured manner. This feature, however, is being approached carefully to ensure it aligns well with Kotlin’s principles.
* Explicit Fields: Providing more control over backing fields for properties.

The team emphasized a careful approach to evolving the language, ensuring new features are well-designed and maintainable. Compiler plugins were also highlighted as an avenue for extending Kotlin’s capabilities.

Kotlin in the Ecosystem: Google’s Investment and Multiplatform Growth

Grace Kloba from Google took the stage to reiterate Google’s strong commitment to Kotlin. She shared insights into Google’s investments in the Kotlin ecosystem, including the development of Kotlin Symbol Processing (KSP) and the continued focus on making Kotlin the default choice for Android development. Google officially supported Kotlin for Android development by early 2017. The Kotlin DSL is now the default for Gradle build scripts in Android Studio, enhancing developer experience with features like semantic highlighting and code completion. Google also actively contributes to the Kotlin Foundation and encourages the community to participate through programs like the Kotlin Foundation Grants Program, which focuses on supporting multiplatform libraries and frameworks.

Kotlin Multiplatform (KMP) was another major highlight, showcasing its growing maturity and adoption. The vision for KMP is to allow developers to share code across various platforms—Android, iOS, desktop, web, and server-side—while retaining the ability to write platform-specific code when needed. The keynote celebrated the increasing number of multiplatform libraries and tools, including KMM Bridge, that simplify KMP development. The future of KMP looks bright, with efforts to further improve the developer experience and expand its capabilities.

Compose Multiplatform and Emerging Technologies

The keynote also showcased the advancements in Compose Multiplatform, JetBrains’ declarative UI framework for building cross-platform user interfaces. A significant announcement was the alpha release of Compose Multiplatform for iOS, enabling developers to write their UI once in Kotlin and deploy it on both Android and iOS, and even desktop and web. This opens up new possibilities for code sharing and faster development cycles for mobile applications.

Finally, the team touched upon Kotlin’s expansion into emerging technologies like WebAssembly (Wasm). JetBrains is developing a new compiler backend for Kotlin targeting WebAssembly with its garbage collection proposal, aiming for high-performance Kotlin code in the browser. Experiments with running Compose applications in the browser using WebAssembly were also mentioned, hinting at a future where Kotlin could offer a unified development experience across an even wider range of platforms. The keynote concluded with an invitation for the community to dive deeper into these topics during the conference and to continue contributing to Kotlin’s vibrant ecosystem.

Links: