How Prime Video Cut UI Latency 7.6x by Switching to Rust
It takes less than a minute to find programmers singing praises for Rust on an online forum. Over the last few years, Rust has been one of the most admired programming languages in Stack Overflow surveys. Naturally, some of the largest companies today are reaping the benefits of the various advantages the language provides. Companies around the world, such as Atlassian, Discord, Figma, Meta, and Mozilla, have significantly benefited from implementing Rust in production. In fact, more than 90 companies across a wide range of industries now rely on Rust for production today at various levels of their tech stack. At QCon San Francisco last November, Alexandru Ene, a principal engineer at Amazon Prime Video, revealed that the company migrated the user interface for its living room devices to a unified Rust-based architecture compiled to WebAssembly. Previously, the app employed a dual tech stack: business logic was developed in React and JavaScript, while low-level engine components were managed using Rust and WebAssembly. This migration has benefited Prime Video in several ways. Ene mentioned that many of the animations and smooth page transitions users experience in the app today are made possible by Rust—features that weren’t achievable with TypeScript and React due to performance limitations. For example, the Prime Video app on a lower-end device experienced almost 250 milliseconds of latency when transitioning from the main page to the collection page. With Rust, the latency dropped to 33 milliseconds. This represents over a 7 fold reduction in latency. Ene also showcased additional elements and animations within the app, where the latency was significantly reduced. Ene said that when the company built a prototype with React, it felt “much nicer and more responsive”. “It just convinced people instantly that it’s worth the risk of building a UI in Rust and WebAssembly,” he said.It’s only fair that Prime Video regarded it as a ‘risk’, considering that Rust is far from being popular or widely explored for front-end development like React and JavaScript. So how did the team pull it off? ‘The Problem Was JavaScript, So We Don’t Have That Anymore’ Before the migration, the business logic, including the interface and user interactions, was developed using React and JavaScript. Meanwhile, performance-critical parts like rendering and animations were handled by a low-level engine built in Rust and WebAssembly, with some components in C++. These two layers communicated through a message bus, enabling the JavaScript side to send commands to the Rust engine to trigger visual updates on the screen. While integrating Rust in this tech stack brought “huge gains” in the fluidity of animations, it didn’t lead to any improvement in latency. (Source: Alexandru Ene’s presentation at the QCon San Francisco, November 2024.) Prime Video then revamped the architecture by building a Rust-based UI software development kit (SDK), which was compiled for WebAssembly for efficient cross-device deployment. “Everything is now in Rust. It’s one single language. You don’t even have the message bus to worry about,” Ene said. “The problem was JavaScript, so we don’t have that anymore.” However, he acknowledged that Rust lacks a substantial number of libraries for UI programming and is not fully developed in this area yet. In response, Amazon Prime Video created a custom UI SDK inspired by React, SolidJS, and Leptos. It utilises ergonomic macros for named, optional arguments and uses reactive signals, memos, and effects to propagate updates. The production-ready framework incorporates an entity component system (ECS) architecture that separates UI data from behavior, essential widgets, and event handling. The framework then compiles to WebAssembly, powering all the living room devices. “We switched them (developers) with our Rust UI SDK with no loss in productivity,” Ene said. While Amazon seems to have cracked the code for using Rust in UIs, promising efforts are underway to develop more effective frameworks and abstractions like these. For example, a project named Are We GUI Yet? tracks Rust-native and cross-platform GUI solutions, highlighting bindings to existing libraries and experimental Rust-based approaches and providing developers with a clear overview of this growing ecosystem. A 40x Speed Boost with Rust + WebAssembly Over JavaScript That said, several other developers have observed that using Rust and WebAssembly can enhance the performance of JavaScript. In a Medium article, Yuji Isobe, vice president of engineering at NearMe, shared how he significantly enhanced JavaScript performance using Rust and WebAssembly. Isobe, initially skeptical about the practicality of WebAssembly, experimented by rewriting a JavaScript-based ULID generator—a widely used library for generating unique, sortable identifiers—in Rust and then compiling it to WebAssembly. This delivered remarkable results, with the implementation executing approximately 40 times faster than the original JavaScript version. Initially, the performance improvement was about 10 times faster, but Isobe enhanced the implementation further by minimising unnecessary memory allocation, precomputing repeated operations, and streamlining data handling. With these enhancements, he extracted even greater efficiency from the WebAssembly module. “WASM’s (WebAssembly) speed comes from its low-level binary format, simple memory model, and ahead-of-time compilation. This minimises overhead, allowing performance close to native code,” Isobe said. Another developer, Chris Biscardi, explained in a YouTube video how he built a web UI for his website using Rust and the administrative UI for content management using the Leptos framework. Biscardi also revealed that he used Axum as the server framework for both the interface and the associated API service. “The experience is as good as any JavaScript-based site that I could have built, in my opinion,” he said.
“The problem was JavaScript, so we don’t have that anymore.”
“The problem was JavaScript, so we don't have that anymore.”
["AI (Artificial Intelligence)", "Rust"]
["Go", "API", "AI", "ML", "JavaScript", "TypeScript", "C++", "Rust", "R", "Java", "AI (Artificial Intelligence)"]
["AI", "ML", "R", "JavaScript", "TypeScript", "Go", "Rust", "Java", "C++", "API"]
Supreeth is an engineering graduate who is curious about the world of artificial intelligence and loves to write stories on how it is solving problems and shaping the future of humanity.