使用 Rust 和 WebAssembly 重建 Prime Video UI

BT

InfoQ 软件架构师通讯

架构师或有志成为架构师的你每月需要了解的内容概览。 查看示例 输入你的电子邮箱地址 选择你的国家 Select your country AfghanistanÅlandAlbaniaAlgeriaAmerican SamoaAndorraAngolaAnguillaAntarcticaAntigua and BarbudaArgentinaArmeniaArubaAustraliaAustriaAzerbaijanBahamasBahrainBangladeshBarbadosBelarusBelgiumBelizeBeninBermudaBhutanBoliviaBonaire, Sint Eustatius, and SabaBosnia and HerzegovinaBotswanaBouvet IslandBrazilBritish Indian Ocean TerritoryBrunei DarussalamBulgariaBurkina FasoBurundiCambodiaCameroonCanadaCape VerdeCayman IslandsCentral African RepublicChadChileChinaChristmas IslandCocos (Keeling) IslandsColombiaComorosCongo (Democratic Republic)Congo (People's Republic)Cook IslandsCosta RicaCote D'IvoireCroatiaCubaCuraçaoCyprusCzech RepublicDenmarkDjiboutiDominicaDominican RepublicEast TimorEcuadorEgyptEl SalvadorEquatorial GuineaEritreaEstoniaEthiopiaFalkland Islands (Malvinas)Faroe IslandsFijiFinlandFranceFrench GuianaFrench PolynesiaFrench Southern TerritoriesGabonGambiaGeorgiaGermanyGhanaGibraltarGreeceGreenlandGrenadaGuadeloupeGuamGuatemalaGuernseyGuineaGuinea-BissauGuyanaHaitiHeard Island and McDonald IslandsHondurasHong KongHungaryIcelandIndiaIndonesiaIranIraqIrelandIsle of ManIsraelItalyJamaicaJapanJerseyJordanKazakhstanKenyaKiribatiKosovoKuwaitKyrgyzstanLaosLatviaLebanonLesothoLiberiaLibyaLiechtensteinLithuaniaLuxembourgMacauMacedoniaMadagascarMalawiMalaysiaMaldivesMaliMaltaMarshall IslandsMartiniqueMauritaniaMauritiusMayotteMexicoMicronesiaMoldovaMonacoMongoliaMontenegroMontserratMoroccoMozambiqueMyanmarNamibiaNauruNepalNetherlandsNetherlands AntillesNew CaledoniaNew ZealandNicaraguaNigerNigeriaNiueNorfolk IslandNorth KoreaNorthern Mariana IslandsNorwayOmanPakistanPalauPalestinian TerritoryPanamaPapua New GuineaParaguayPeruPhilippinesPitcairnPolandPortugalPuerto RicoQatarReunionRomaniaRussian FederationRwandaSaint HelenaSaint Kitts and NevisSaint LuciaSaint MartinSaint Pierre and MiquelonSaint Vincent and the GrenadinesSaint-BarthélemySamoaSan MarinoSao Tome and PrincipeSaudi ArabiaSenegalSerbiaSeychellesSierra LeoneSingaporeSint MaartenSlovakiaSloveniaSolomon IslandsSomaliaSouth AfricaSouth Georgia and the South Sandwich IslandsSouth KoreaSouth SudanSpainSri LankaSudanSurinameSvalbard and Jan MayenSwazilandSwedenSwitzerlandSyriaTaiwanTajikistanTanzaniaThailandTogoTokelauTongaTrinidad and TobagoTunisiaTurkeyTurkmenistanTurks and Caicos IslandsTuvaluUgandaUkraineUnited Arab EmiratesUnited KingdomUnited States Minor Outlying IslandsUruguayUSAUzbekistanVanuatuVatican City (Holy See)VenezuelaVietnamVirgin Islands (British)Virgin Islands (U.S.)Wallis and FutunaWestern SaharaYemenZaireZambiaZimbabwe I consent to InfoQ.com handling my data as explained in this Privacy Notice. We protect your privacy. Close QCon AI New York (Dec 16-17): Get patterns from senior practitioners implementing real-world AI now. Register Now Close Toggle Navigation Facilitating the Spread of Knowledge and Innovation in Professional Software Development English edition

Write for InfoQ Search Sign Up / Login Email Password Forgot password ? InfoQ Account Email Back to login Resend Activation Back to login

Login with:

Google Microsoft Twitter Facebook

Don't have an InfoQ account?

Sign Up Logo - Back to homepage News Articles Presentations Podcasts Guides

Topics

Development

Featured in Development

Colby Morgan discusses practical strategies and technical examples for building accessible and inclusive XR experiences. Learn about their core design principles, including accessibility at the start, invisible features, simplicity, and layered depth, using Walkabout Mini Golf as a case study. Building Inclusive Mini Golf: a Practical Guide to Accessible XR Development

All in development Follow Topic Architecture & Design

Featured in Architecture & Design

Mykhailo Brodskyi discusses critical software supply chain security risk categories relevant to FinTech and explains effective mitigation strategies. Drawing from real project case studies, he shares insights to protect systems from vulnerabilities and ensure platform security and resilience. Demo: third-party library risk mitigation through software bill of materials generation and analysis. Comprehensive Approaches to Software Supply Chain Security

All in architecture-design Follow Topic AI Infrastructure

Featured in AI, ML & Data Engineering

Lexy Kassan discusses the critical aspects of responsible AI, focusing on regulatory updates like the EU AI Act and its implications for FinTech. She explains the levels of responsible AI, from ethical principles to practical implementation, including AI governance. Explore FinTech's disruptive AI response, open-source use, workforce shifts, review boards & risk frameworks. Responsible AI for FinTech

All in ai-ml-data-eng Follow Topic Culture & Methods

Featured in Culture & Methods

Shawna Martell shares practical strategies to effectively manage legacy code and tech debt. Learn how to lift existing code, gain buy-in for improvements, and build new systems with future maintainability in mind using encapsulation, testing, and linting. She explains the Strangler Fig pattern and provides actionable advice for creating code that ages gracefully and minimizes future headaches. Building Tomorrow’s Legacy Code, Today

All in culture-methods Follow Topic DevOps

Featured in DevOps

This article provides SREs with a checklist for managing Kubernetes in production environments. It identifies common challenges including resource management, workload placement, high availability, health probes, storage, monitoring, and cost optimization. By implementing consistent GitOps automation across these areas, teams can significantly reduce complexity, and prevent downtime. Checklist for Kubernetes in Production: Best Practices for SREs

All in devops Follow Topic Events

Helpful links

Choose your language

InfoQ Dev Summit Boston - image InfoQ Dev Summit Boston Learn how senior software developers are solving the challenges you face. Register now with early bird tickets. InfoQ Dev Summit Munich - image InfoQ Dev Summit Munich Learn practical solutions to today's most pressing software challenges. Register now with early bird tickets. QCon San Francisco - image QCon San Francisco Explore insights, real-world best practices and solutions in software development & leadership. Register now. QCon AI New York - image QCon AI New York Learn how leading engineering teams run AI in production-reliably, securely, and at scale. Register now. InfoQ Homepage Presentations Rebuilding Prime Video UI with Rust and WebAssembly Development [Architecting Scalable, Secure Multi-Agent Systems (Webinar, Apr 15th) ](https://www.infoq.com/presentations/prime-video-rust/<https:/www.infoq.com/url/t/b0e22931-21e2-423d-a64f-ad2519bac41b/?label=Boomi-EventPromoBox >)

使用 Rust 和 WebAssembly 重建 Prime Video UI

Like

View Presentation

Speed:

Download

48:06

摘要

Alexandru Ene 详细介绍了使用新的 UI SDK,该 SDK 使用 Rust 语言为 Prime Video 构建,目标是客厅设备。

简介

Alexandru Ene 是亚马逊 Prime Video 的首席工程师。他之前曾在视频游戏、游戏引擎领域工作,并且对交互式媒体和高性能系统充满热情。

关于会议

软件正在改变世界。QCon San Francisco 致力于促进开发者社区的知识传播和创新,从而推动软件开发。QCon 是一场由从业者驱动的会议,专为技术团队负责人、架构师、工程主管和项目经理设计,他们能够影响其团队的创新。

INFOQ 活动

架构可扩展、安全的多代理系统

演讲者:Michael Bachman - Boomi 架构与 AI 战略主管 由 BOOMI 赞助

API 优先的创新:了解 Visa、DocuSign 和 Heineken 如何推动 AI 转型

立即注册 由 MICROSOFT 赞助

Agentic AI 的设计模式:构建可扩展的事件驱动系统

演讲者:Tyler Jewell - Akka 首席执行官,Richard Li - Amorphous Data 创始人 由 AKKA 赞助

文本记录

Ene: 我们将讨论如何使用 Rust 和 WebAssembly 为客厅设备重建 Prime Video UI,以及我们是如何走到这一步的。我是 Alex。我已经在亚马逊的 Prime Video 担任首席工程师大约八年了。实际上,我们已经在客户端的技术栈中使用 Rust 有一段时间了。我们有 WebAssembly 和 Rust 的低级 UI 引擎。之前我从事视频游戏、游戏引擎和类似的交互式应用程序工作。我在交互式应用程序方面有相当多的经验。

内容

我将谈谈这个领域中的挑战,因为客厅设备包括机顶盒、游戏机、流媒体电视棒、电视等。人们通常不会为这些设备开发 UI,它们有自己特殊的挑战,因此我们将逐一介绍这些挑战。然后,我将向你展示在我们用 Rust 重写所有内容之前,Prime Video App 的架构是什么样的。我们有一个双技术栈,业务代码使用 React 和 JavaScript,引擎的低级部分使用 Rust 和 WebAssembly,其中还有一些 C++。然后,我将向你展示一些使用我们新的 Rust UI SDK 的代码,以及它的外观,这是我们现在在生产环境中使用的。我们将稍微讨论一下该代码如何与我们现有的低级引擎一起工作,以及所有内容是如何组织的。最后,我们将简单地讨论一下结果和经验教训。

这个领域的挑战

正如我所说,客厅设备包括游戏机、流媒体电视棒、机顶盒等。它们有自己的挑战,其中一些是显而易见的。性能差异巨大。我们说的是 PlayStation 5 Pro,一个超级棒的游戏机,有很多性能,但也有 USB 供电的流媒体电视棒。Prime Video 在所有这些设备类型上运行相同的应用程序。显然,性能对我们来说非常重要。我们不能为每种设备类型配备专门的团队,例如,一个团队负责机顶盒,另一个团队负责游戏机,因为这样所有事情都会崩溃。当你构建一个功能时,你必须为所有设备构建它。我们构建一次,然后在所有这些设备类别上部署。我所说的这个应用程序不部署在移动设备上,例如 iPhone、iOS、移动设备上没有。这仅限于客厅设备。再说一次,性能范围非常广泛。我们正在努力使我们的代码尽可能优化。

通常,高性能代码是你在本地编译的代码。例如,Rust 编译为本地代码,C++ 编译为本地代码,但这在这个领域还不够,我们将看到原因。另一个痛点和挑战是这些设备之间的硬件功能差异。作为 SDK 的开发者,我们需要考虑很多合理的后备方案,应用程序开发者编写应用程序代码和应用程序行为时,他们不需要考虑每一个细微的硬件差异。我们尝试使用一些合理的默认值。但这并不总是可能的,因此我们使用诸如功能标志之类的模式来让他们有更多的控制权。这是一件相当具有挑战性的事情。

另一件事是,我们正在努力使这个应用程序尽可能快,并为每个客户提供尽可能多的功能,但是在这些设备类型上更新本地代码非常困难。部分原因是这些设备甚至没有应用商店,大多数都没有。也许它会随着固件更新而上升。这是一个痛苦。这需要与拥有该平台的第三方进行手动交互。即使在确实有应用商店的地方,如果你尝试在应用商店更新应用,这也是一个挑战。你需要等待。这很可能是一个手动过程。我们在空中下载的代码(如 JavaScript、WebAssembly 等),相当容易,和在设备上运行的代码(速度非常快,但是很难更新)之间存在着这种紧张关系。我们希望拥有快速迭代周期。在短时间内更新应用程序对我们来说非常重要。

再说一次,这就是应用程序今天的样子。我已经在这里八年了,我们已经更改了很多次。我确信它将来还会再次更改,就像 UI 经常发生的那样。我们向其中添加了频道、直播活动以及许多在起始版本中没有的新功能。我们之所以能够做到这一点,部分原因在于我们从一开始就专注于可更新性。这些应用程序中的大多数都使用像 JavaScript 这样的语言编写,我们可以基本上更改其中的所有内容,并添加所有这些功能,几乎无需去触及底层的本地代码。我将向你展示架构以及它的外观。

今天,如果开发人员添加一些代码、更改一个功能、修复一个错误,或者对 UI 进行任何更改,该代码都将通过完整的 CI/CD 管道,没有任何手动测试。我们在 Linux 等虚拟设备和拥有设备群的物理设备上进行测试。一旦所有这些测试都通过,你就可以在客厅的电视上获得这种新体验。这比该平台的本机应用程序更新要快得多。

现在,你将看到它的工作方式,并且会看到一些功能。这是一堆我正在制作的测试配置文件,因为我正在测试东西。我们有一些像布局动画这样的东西,因此整个布局都会重新计算。这是今天在生产环境中运行的 Rust 应用程序。布局动画是以前使用 JavaScript 和 React 无法实现的事情,现在它们可以正常工作了。当你看到这个东西变大时,所有东西都会在页面上重新排序。这些都是目前仅通过 Rust 的性能才有可能实现的事情。由于性能限制,使用 TypeScript 和 React 几乎无法实现即时页面转换。这现在已经上线了,这就是它的样子,因此你对其中发生的事情有了一个概念。稍后我们将稍微回到布局动画和这些东西。对于不是 UI 工程师或者不太了解的人来说,这张幻灯片将教会你你需要了解的关于 UI 编程的一切。

基本上,每个 UI 都是一个节点树,而 UI SDK 的工作就是尽快地操作这个树,以响应用户输入或发生的一些事情,例如一些事件。你要么更改节点上的属性,例如,你可能会为某个值(如位置)设置动画,然后 UI 引擎需要负责更新此树并创建新节点、删除新节点,具体取决于业务逻辑代码告诉你的内容。这些节点可以是视图节点,它们可能只是一个矩形。然后,文本节点非常常见,图像节点也是如此。没什么太复杂的。令人烦恼的是它是一棵树,但是我们将继续前进,因为我们仍然有一棵树,即使在我们的 Rust 应用程序中,我们也没有进行创新,但是拥有这个心智模型非常重要。在我们的 UI 引擎中,我们称之为