Share
Embed
What_s_up_Wasm_in_Go_.pdf
Taku Fukushima
March 13, 2023
Transcript
14 slides
-
2 Abstract of Wasm binary written in Rust Agenda Demo
What’s up Wasm in Go? Summary 02 03 04 01 -
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 -
5 画像 Original data has all US address information in
a line Our CSV data -
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 -
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 -
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 -
11 Future? • GC • Threads • Does Go dream
of lightweight Wasm binary output? New Wasm standards are added -
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