Saying goodbye to asm.js

Saying goodbye to asm.js

告别 asm.js

Axe-time, sword-time, shields are sundered, Wind-time, wolf-time, ere the world falls. – Völuspá, Poetic Edda 斧之时代,剑之时代,盾牌破碎,风之时代,狼之时代,世界崩塌之前。——《诗体埃达》,《女巫的预言》

As of Firefox 148, SpiderMonkey’s asm.js optimizations are disabled by default, and we plan to remove the code entirely in a future release. If you maintain a site that uses asm.js, nothing will break. asm.js is just a subset of plain JavaScript, so the code keeps running through our regular JIT just like any other script. That said, recompiling to WebAssembly will get you faster execution and smaller binaries. 从 Firefox 148 版本开始,SpiderMonkey 的 asm.js 优化功能已被默认禁用,我们计划在未来的版本中彻底移除相关代码。如果您维护的网站使用了 asm.js,这不会导致任何功能中断。asm.js 本质上只是普通 JavaScript 的一个子集,因此代码依然可以通过我们常规的 JIT(即时编译)引擎运行,就像其他脚本一样。话虽如此,重新编译为 WebAssembly 将为您带来更快的执行速度和更小的二进制文件体积。

History

历史

asm.js was Mozilla’s response to the question posed by NaCl and PNaCl: how can the web run code at native speeds? The idea was clever: pick a strict, statically-typed subset of JavaScript that an engine could recognize on the fly and compile down to native code. We could get performance similar to NaCl/PNaCl and still have code live inside web content and use web API’s (no separate sandbox, IPC, or alternative API’s). asm.js 是 Mozilla 对 NaCl 和 PNaCl 所提出问题的回应:Web 如何才能以原生速度运行代码?这个构思非常巧妙:选取一个严格的、静态类型的 JavaScript 子集,让引擎能够即时识别并将其编译为原生代码。这样我们既能获得媲美 NaCl/PNaCl 的性能,又能让代码直接运行在 Web 内容中并调用 Web API(无需独立的沙箱、IPC 或替代 API)。

asm.js shipped in Firefox 22 back in 2013 and was a success. It let projects like Unity and Unreal ship C/C++ codebases to the web for the first time, using just standard web technologies. The Epic Citadel demo was ported to the web in just four days. It was a landmark achievement, and a fond memory for the original asm.js team. asm.js 于 2013 年在 Firefox 22 中发布并取得了成功。它让 Unity 和 Unreal 等项目首次能够仅使用标准 Web 技术,将 C/C++ 代码库发布到 Web 上。Epic Citadel 演示程序仅用了四天时间就移植到了 Web 端。这是一项里程碑式的成就,也是 asm.js 创始团队的美好回忆。

asm.js proved that we could run code at near-native speed on the web using just web technologies. This opened the door to WebAssembly, which shipped several years later in Firefox 52. Without asm.js, we likely wouldn’t have WebAssembly. asm.js 证明了我们仅使用 Web 技术就能在 Web 上以接近原生的速度运行代码。这为几年后在 Firefox 52 中发布的 WebAssembly 打开了大门。如果没有 asm.js,我们很可能就不会有 WebAssembly。

Why now?

为什么要现在移除?

So why turn it off? WebAssembly has succeeded, and asm.js usage has mostly migrated over. Keeping the asm.js path alongside WebAssembly costs us maintenance time and gives us extra attack surface in the VM. If you are shipping asm.js content, please consider recompiling to WebAssembly! Our WebAssembly pipeline is significantly more advanced than the asm.js one ever was. You should see faster execution and smaller binaries. 那么为什么要关闭它呢?WebAssembly 已经取得了成功,asm.js 的使用量也大多已经迁移过去。在保留 WebAssembly 的同时维护 asm.js 路径会消耗我们的维护时间,并给虚拟机(VM)增加额外的攻击面。如果您正在发布 asm.js 内容,请考虑重新编译为 WebAssembly!我们的 WebAssembly 流水线比 asm.js 的任何版本都要先进得多。您将会看到更快的执行速度和更小的二进制文件。

Ragnarök

诸神黄昏

The asm.js compiler is called OdinMonkey. As was foretold long ago, OdinMonkey must meet his fated doom. The bug Ragnarök tracks the “Twilight of OdinMonkey”. All is not lost however, for born of OdinMonkey is BaldrMonkey, our WebAssembly optimizing compiler. OdinMonkey may be swallowed whole by the wolf, Fenrir, but BaldrMonkey will rule over the reborn world alongside RabaldrMonkey (“commotion”), our WebAssembly baseline compiler. asm.js 编译器被称为 OdinMonkey。正如很久以前所预言的那样,OdinMonkey 必须迎接他命中注定的毁灭。Bug 追踪器中的“诸神黄昏”(Ragnarök)记录了“OdinMonkey 的黄昏”。然而,一切并未终结,因为从 OdinMonkey 中诞生了 BaldrMonkey,即我们的 WebAssembly 优化编译器。OdinMonkey 可能会被巨狼芬里尔(Fenrir)整个吞下,但 BaldrMonkey 将与我们的 WebAssembly 基准编译器 RabaldrMonkey(意为“骚动”)一起统治重生的世界。

On this Odin’s day (Wednesday) we thank OdinMonkey for thirteen years of service. Skål! 在这个奥丁之日(周三),我们感谢 OdinMonkey 十三年的服务。干杯!

Then fields unsowed bear ripened fruit, all ills grow better, and Baldr comes back; Baldr and Hoth dwell in Hropt’s battle-hall. – Völuspá, Poetic Edda 届时,未播种的田野将结出成熟的果实,一切苦难都将好转,巴德尔(Baldr)将归来;巴德尔与霍德(Hoth)将居住在奥丁的战神殿中。——《诗体埃达》,《女巫的预言》