Skip to main content

WebAssembly

WebAssembly (sometimes abbreviated Wasm) defines a portable binary-code format and a corresponding text format for executable programs and software interfaces for facilitating interactions between such programs and their host environment. WebAssembly

Assembly languages in general consists of simple and atomic operations that the processor can follow. For example, let's consider the following add.c C code.

#include <stdio.h>

int add(int x, int y) { return x + y; }

int main() {
printf("Hello World\n");
printf("1 + 2 = %d \n", add(1, 2));
return 0;
}
❯ gcc add.c
❯ ./a.out
Hello World
1 + 2 = 3

It is a very straightforward C code that returns the sum of the two integers provided as input. We can convert this C code into WebAssembly with a build tool called Emscripten. After running the following command, we can get the WASM version of the function int add(int x, int y).

emcc add.c -o index.html

8692F9.png

We can now create a local server to test this example.

❯ npx serve .

┌───────────────────────────────────────────────────┐
│ │
│ Serving! │
│ │
│ - Local: http://localhost:3000 │
│ - On Your Network: http://192.168.8.100:3000 │
│ │
│ Copied local address to clipboard! │
│ │
└───────────────────────────────────────────────────┘

And we can confirm that it is working as expected.

56155E.png

Interesting Implementations

SQLite Wasm in the browser backed by the Origin Private File System - Chrome Developers

  • SQLite based on Web Assembly
  • Binding a low-level sqlite3 API which is as close to the C one as feasible in terms of usage.
  • A higher-level object-oriented API, more akin to sql. js and Node. Js-style implementations speak directly to the low-level API. This API must be used from the same thread as the low-level API.
  • A Worker-based API that speaks to the previous APIs via Worker messages. This one is intended for use in the main thread, with the lower-level APIs installed in a Worker thread and talking to them via Worker messages.
  • A Promise-based variant of the Worker API that entirely hides the cross-thread communication aspects from the user.
  • Support persistent client-side storage using JavaScript APIs, including the Origin Private File System (OPFS).

Links to This Note

WebNPU API를 상상하다

... -WebAssembly는 웹에서 CPU의 온전한 성능을 개방한다.

WebGPU

- It's a **stand-alone TypeScript+Rust/WASMlibrary** with its own React-like run-time. ...

WebAssembly

... can convert this C code intoWebAssemblywith a build tool called [Emscripten](https://emscripten.org/index.html). ...

Web Graphics

... - Usually uses WebGPU andWASM

WasmEdge

... [WasmEdge](https://wasmedge.org/): Edge forWebAssembly

Stories Behind Satori

... Converting it intoWASMwill also benefit by targeting [[Web ...

Snowpack으로 WASM 시작하기

- ffmpeg.wasm은 Chrome을 사용해 구동하기 (2020/11 기준)

Satori

... solutions by using Vercel Edge Functions,WebAssembly, and a brand new core ...

Ruffle

... web browsers via Rust andWebAssembly

Proposal of Research 2023-03-28

... as Web Workers, SharedArrayBuffer, andWebAssembly, iiframe will revolutionize how web ...

Proposal of Research 2023-01-10

... we can push it further, allowingWASMfiles to take advantage of multi-threaded ...

Project PIRI Initial Proposal

... Fully-Fledged, and Universal Web Player usingWebAssembly

Programmable Web

... something like the QuickJS Sandbox insideWebAssemblycan provide a more secure way ...

Imagining WebNPU API

... -WebAssemblyunlocks the bare-metal power of CPUs. ...

How is WebAssembly cross-platform when Assembly is not

... -WebAssemblyis like Assembly, except that ...

Dioxus

... UseWASM

Deno Deploy

... - TypeScript,Wasm, ES Modules

Cloudflare Worker

... to create and deploy JavaScript orWebAssemblycode at the edge network of ...

2023-02-16

... 2021 [we announced WebContainers](https://blog.stackblitz.com/posts/introducing-webcontainers/), a novelWebAssembly-based operating system that enables Node.js ...

2023-01-13

... -WASM

2022-10-15

... -WebAssembly. [paradust7/minetest-wasm: Experimental Minetest build for ...

2022-10-14

... -WebAssembly

2022-06-14

... -WASM과는 당장은 무관하다.