SA
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/WASM library with its own React-like ...

WebAssembly

... convert this C code into WebAssembly with a build tool called ...

Web Graphics

- Usually uses WebGPU and WASM

WasmEdge

WasmEdge: Edge for WebAssembly

Stories Behind Satori

Converting it into WASM will also benefit by targeting ...

Snowpack으로 WASM 시작하기

... 문장을 통해 `ffmpeg.wasm`을 설치한다. (실제 WASM 파일은 사용자의 웹페이지에서는 CDN을 통해 ...

Satori

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

Ruffle

... Browser|web browsers via Rust and WebAssembly

Proposal of Research 2023-03-28

... Web Worker|Web Workers, SharedArrayBuffer, and WebAssembly, iiframe will revolutionize how web ...

Proposal of Research 2023-01-10

... watching the very beginning of WebAssembly, which allows high-performance applications to ...

Project PIRI Initial Proposal

... and Universal Web Player using WebAssembly

Programmable Web

... like the QuickJS Sandbox inside WebAssembly can provide a more secure ...

Imagining WebNPU API

- WebAssembly unlocks the bare-metal power of ...

How is WebAssembly cross-platform when Assembly is not

- WebAssembly is like Assembly, except that

Dioxus

Use WASM

Deno Deploy

- TypeScript, Wasm, ES Modules

Cloudflare Worker

... create and deploy JavaScript or WebAssembly code at the edge network ...

2023-02-16

... we announced WebContainers, a novel WebAssembly-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과는 당장은 무관하다.