Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What_s_up_Wasm_in_Go_.pdf

Taku Fukushima
March 13, 2023
85

 What_s_up_Wasm_in_Go_.pdf

Taku Fukushima

March 13, 2023
Tweet

Transcript

  1. 2 Abstract of Wasm binary written in Rust Agenda Demo

    What’s up Wasm in Go? Summary 02 03 04 01
  2. 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
  3. 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
  4. 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
  5. 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
  6. 11 Future? • GC • Threads • Does Go dream

    of lightweight Wasm binary output? New Wasm standards are added
  7. 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