Slide 1

Slide 1 text

1 What’s up Wasm in Go? GoでWebAssembly(Wasm)って今どんな感じなんでしたっけ? Taku Fukushima mercari.go #21 Feb 28, 2023

Slide 2

Slide 2 text

2 Abstract of Wasm binary written in Rust Agenda Demo What’s up Wasm in Go? Summary 02 03 04 01

Slide 3

Slide 3 text

3 Abstract of Wasm binary written in Rust Chapter 1

Slide 4

Slide 4 text

4 Goal: USPS address lookup service ● Required in customers’ address management ● ZIP Code validation and address completion in forms ● Current status: gRPC API in a microservice ● Address information is a static data ○ 41,704 lines of CSV: 1.6 MiB ○ Monthly updated ○ We retrieve uniquely formatted data from USPS, parse it and generate a CSV file with K8s CronJob ● No JS/browser dependency ZIP Code → Address Information

Slide 5

Slide 5 text

5 画像
 Original data has all US address information in a line Our CSV data

Slide 6

Slide 6 text

6 Make it Wasm binary ● CSV → binary data via Rust’s Build Scripts ○ We don’t want to load CSV at runtime ○ We want address data in binary ● Embed the binary into code via include_bytes! ● Compacted address info stored in Trie ○ std::collections::HashMap → rust-phf → fs_trie ● Export Wasm binary and JS compatibility layer via wasm-pack ZIP Code in string → Address Information in JSON

Slide 7

Slide 7 text

7 Demo Chapter 2

Slide 8

Slide 8 text

8 What’s up Wasm in Go? Chapter 3

Slide 9

Slide 9 text

9 My past experience ● Go compiler has WASM target by default ○ GOOS=js GOARCH=wasm ○ With JavaScript glue ■ $(go env GOROOT)/misc/wasm/wasm_exec.js ○ Relatively bigger size Wasm binary ● TinyGo can generate binary with smaller footprint ○ tinygo build -o module.wasm -target wasi . Wasm binary generated from Go code contains Go runtime

Slide 10

Slide 10 text

10 My current experience ● Still TinyGo is a good option ● go:embed can be used embedding binary data in Wasm binary ● Nice trie/radix tree library is needed with gob/binary format compatibility ○ github.com/hashicorp/go-immutable-radix did not get along with gob ○ * I just could not find one and there could be any out there Not changed so much since last time

Slide 11

Slide 11 text

11 Future? ● GC ● Threads ● Does Go dream of lightweight Wasm binary output? New Wasm standards are added

Slide 12

Slide 12 text

12 Summary Chapter 4

Slide 13

Slide 13 text

13 Go in Wasm ● Default Go compiler supports ● Still TinyGo is a good option ● We could see some improvements in the future? ● Various matured Wasm runtime ○ github.com/wasmerio/wasmer-go ○ github.com/tetratelabs/wazero ○ … Go has nice Wasm supports

Slide 14

Slide 14 text

14 End of Slides EOS