惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
爱范儿
爱范儿
人人都是产品经理
人人都是产品经理
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园_首页
V
Visual Studio Blog
Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
博客园 - 司徒正美
大猫的无限游戏
大猫的无限游戏
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
月光博客
月光博客

ByteofDev

Turning Claude into Postgres so I can raise a Series A Making Postgres 42,000x slower because I am unemployed A Quick(ish) Introduction to Tuning Postgres JavaScript numbers have an (adoption) problem My 2025 JavaScript Wishlist JavaScript Benchmarking Is a Mess Replacing Disqus Commenting A deep dive into distributed database architectures 10 ways to speed up web image loading Tailwind has a scalability problem. How can we solve that? Lerna vs Turborepo vs Rush: Which is better in 2023? The 6 JavaScript Projects to watch in 2023 Top 5 Alternatives to React in 2023 How to use ESM on the web and in Node.js React vs Svelte: Which is better in 2023? 10 ways to speed up JavaScript loading What is Bun, and does it live up to the hype? State of JS 2021 Results and Analysis State of the Web: React 10 ways to speed up web font loading State of the Web: Atomic CSS State of the Web: Static Site Generators State of the Web: Bundlers & Build Tools Migrating ByteofDev from SvelteKit to Astro State of the Web: Serverless Functions State of the Web: Deno Array.map() versus Array.forEach() A quick introduction to JavaScript Maps How I Built the Fastest JavaScript Data Differ When you should and shouldn't use React
State of the Web: WebAssembly
Jacob Jackson · 2022-01-02 · via ByteofDev

WebAssembly (WASM) is a new assembly-like language on the web that aims to allow developers to write fast, portable code in the language of their choice. It is currently usable in all modern browsers and Node.js, and some WebAssembly only runtimes.

Background of WebAssembly

A coalition of browsers created WebAssembly in 2015 as a successor to asm.js and Google Native Client. Later, in 2017, it was released on all modern browsers, and in 2018 a formal spec was released. WebAssembly is a binary format that allows for cross-platform execution of sandboxed code without using JavaScript. It is also designed to be compact and be parsed and executed significantly faster than JavaScript. It can be used on the web and servers to allow secure and portable sandboxed code execution.

Why WebAssembly is significant

Security

WebAssembly is a sandboxed language, and because of that, it is secure. Tools like Wasmer allow running WASM outside of the web with limited system calls and metering CPU cycles. WebAssembly’s security has made lightweight serverless function environments like Cloudflare Workers, Fastly Compute@Edge, and WasmEdge increasingly adopt WebAssembly. WebAssembly can even be more secure than JavaScript on the web because of the simplicity of the compiler. Unlike JavaScript, which has a complicated three-tiered JIT compiler/runtime, which can be very buggy. In contrast, because WebAssembly is strongly typed and closer to machine code, the compilers for WebAssembly can be more straightforward and, therefore, more secure. Firefox even uses WebAssembly for font shaping because of its sandboxing capabilities.

Speed

WebAssembly is very fast to both parse and execute. Even though it is relatively new to the web world, it still can be significantly faster than JavaScript. For parsing speeds, WebAssembly is already substantially more rapid than JavaScript. Firefox’s WebAsssembly VM can run WebAssembly faster than it is received from the network. This removes a significant speed problem with JavaScript. Using WebAssembly, Figma reduced their loading time by 3x. As for execution speeds, WebAssembly still has work before it reaches its full potential, but the early results are promising. Currently, WebAssembly sometimes does better than JavaScript but also sometimes does worse.

Another performance problem with WebAssembly is the high overhead for calling web APIs from WebAssembly. Mozilla has optimized this, but Chrome and Node.js still have this problem. However, WebAssembly performance is improving, and eventually, it might even be possible to get native performance with WebAssembly.

Flexibility

WebAssembly is designed for multi-language support. It has a text format (WAT), but it is tough to use. Currently, you can compile many languages to WebAssembly, like a form of TypeScript, Go, Rust, and C. This makes it so you are not constrained to JavaScript and can instead use another language for reasons like ecosystem, syntax, or code sharing between platforms.

The Current State of WebAssembly

Widespread WebAssembly adoption is still far away, but it is making progress. Now we will look at the state of WebAssembly in web browsers, on servers, and the best languages to use.

Web support

WebAssembly on the web is in its early stages, although you can already build full websites without touching JavaScript. The browser support for WebAssembly is pretty good, with all modern browsers supporting it.

If you are trying to create a complete web application using WebAssembly, the easiest way to do that as of now is using Rust and a framework such as Yew with Trunk. However, because of the small ecosystem, WebAssembly is currently best for small performance focused parts of an application rather than whole applications.

Server support

WebAssembly on the server is quickly growing. WebAssembly offers ultralight isolation, which makes it great for serverless functions because serverless functions need to start rapidly and have a low footprint. For an example of how this works, let’s look at how one of the most popular serverless function services, Cloudflare Workers, operates.

Cloudflare Workers executes serverless functions using V8 isolates rather than containers in separate processes. V8 isolates are lightweight V8 execution environments that start-up significantly faster than traditional sandboxed environments.

However, because isolates are only for the V8 engine, only JavaScript and WebAssembly are supported. Because not everyone wants to use JavaScript, WebAssembly is a popular choice for Cloudflare Workers. In fact, Cloudflare Workers has excellent support for using Rust with WebAssembly, with an officially maintained Rust API. As you can see, WebAssembly is an excellent choice for servers due to how it can execute in a lightweight, secure environment. If you want to look at benchmarks including Cloudflare Workers to show the speed improvements of isolates, here are some.

Language Support

Currently, if you want to use WebAssembly, the best languages to use are Rust or AssemblyScript. Rust has the most extensive ecosystem for WebAssembly, with tools like WASM-Bindgen for binding to JavaScript, WASM-Pack for generating WASM packages, and more. However, even though AssemblyScript has a significantly smaller ecosystem, it can be a good choice for small WebAssembly modules. AssemblyScript is TypeScript with more advanced types, so it is easy to learn if you have previous JavaScript experience. Additionally, AssemblyScript can often be almost as fast as Rust or C WebAssembly, while delivering significantly smaller binaries.

Conclusion

WebAssembly is still new to the world of the web. However, it is already finding a place in lightweight serverless function execution. I hope you have learned something from this, and this wraps up the first article in State of the Web. Thanks for reading!

If you would like to read about more up-and-coming technologies, make sure to sign up for the newsletter!