If I hand you a minute of ground motion sampled at 100 Hz, you have 6,000 numbers. Write them to a miniSEED file and read them back, and you should still have 6,000 numbers, from the same station, starting at the same time. What you shouldn't need is my C compiler.
libmseed already knows how to read and write these seismic waveform records. I wanted that implementation in a Go program without asking everyone who builds the program to install a C toolchain for their target platform. Rewriting the decoder would solve the build problem by giving me a much bigger problem: now I'm responsible for getting the decoder right.
So in mseedio-wasm, I kept the C code. I compiled libmseed to WebAssembly, embedded the module in a Go package, and called it using wazero. The interesting part wasn't getting a C function to run. It was getting its result back as a Go value I could safely keep.
One C Build on My Side
There are two builds here. The one I do when updating libmseed needs Emscripten and make. The one you do when building a Go application doesn't.
Upstream libmseed is pinned as a Git submodule. My build script asks its Makefile for LIB_SRCS rather than maintaining a second list of C files. It checks the requested exports against libmseed.h, adds malloc and free, and invokes emcc with -O3 and -Wl,--no-entry. There is no main to run: what I need from the result is a set of callable functions and a memory to pass data through.
The resulting libmseed.wasm is checked into the repository. On the Go side, the packaging is all of two lines:
//go:embed libmseed.wasm
var wasmBytes []byte
When the application calls Init, the package instantiates WASI Preview 1 in wazero and then instantiates libmseed from those bytes. There's no browser, JavaScript loader, or libmseed.so to find at startup. Nor does the library need the guest to see the host's filesystem: for the ordinary parse path, Go reads the file and passes in the bytes. Mounting a directory is an explicit option for people using the raw file APIs.
A Pointer to a Pointer… Whose Pointer?
Take msr3_parse. On the C side it gets a buffer and an MS3Record ** through which it returns a decoded record. Passing the address of a Go variable would be meaningless: the C code is looking at the module's linear memory, not the Go heap.
Here's what the parse wrapper actually does:
- Copy the input into guest memory. For a buffer of concatenated records, do this once, then advance through it by the number of bytes each record consumed.
- Allocate four bytes in the guest for the output pointer. Pass the offset of that slot to
msr3_parse. Four is correct even on my 64-bit Linux machine: this particular pointer belongs to a wasm32 module.
- After a successful call, read the slot as a little-endian
uint32. That's the address of the MS3Record, not the record itself. Read its fields and follow its sample-buffer pointer inside the guest.
- Copy the result to a Go
Record, then let msr3_free release the C record. The four-byte slot is a separate allocation and gets freed separately.
That last copy is deliberate. A caller can close the runtime and still use record.Samples.Int32; the slice doesn't secretly point into a module that no longer exists. It also marks the limit of the portability trick: the wrapper knows the field offsets of this build's 160-byte MS3Record. Updating the submodule means checking that layout, not just rebuilding the binary and hoping for the best.
Packing Without a Callback
Reading produces a record; writing can produce several. A natural C interface is “call this function every time a packed record is ready.” A Go function isn't a guest C function pointer, though. Instead of building a callback bridge, I used libmseed's generator interface: msr3_pack_init, msr3_pack_next, and msr3_pack_free.
Now Go drives the loop. PackTo can hand the packed bytes to an io.Writer, and the caller can use an ordinary bytes.Buffer or file. I left the C-callback packing functions out of the export list altogether. Sometimes the easiest binding to maintain is the one you don't write.
A Minute of Data with Benchmark
To try it from the repository root, all you need is Go and the committed module. These are the two example programs I ran with CGO disabled:
CGO_ENABLED=0 go run ./example/pack
CGO_ENABLED=0 go run ./example/parse demo.mseed2 demo.mseed3
The packer generates a 1 Hz sine wave as int32 samples and uses Steim-2 to write it in both miniSEED 2 and 3. Here's what came back on Linux/amd64:
| File |
Bytes |
Records |
Samples per record |
demo.mseed2 |
8,192 |
2 |
4,099 + 1,901 |
demo.mseed3 |
6,076 |
2 |
4,099 + 1,901 |
My favorite sanity check is the start time of the second record. In both files the first starts at 12:00:00Z; the second starts at 12:00:40.990000Z. At 100 samples per second, 4,099 samples occupy exactly 40.99 seconds. The file sizes differ, but the record boundary lands on the same sample. That's a more useful check than “it compiled,” even if it isn't a substitute for a full compatibility suite.
Measuring the Same C Library Three Ways
To put real numbers on the boundary cost, I benchmarked the exact same upstream libmseed 3.5.4 source in three configurations on Linux/amd64 (Intel Core i7-1165G7, 4 physical cores, Go 1.27.4):
- Native C:
libmseed.a compiled with -O3 -fPIC, timed directly with clock_gettime(CLOCK_MONOTONIC).
- Go + CGO: the same C adapter called from Go through
CGO_ENABLED=1. Each benchmark crosses CGO once per window and reuses caller-owned buffers (0 allocs/op)—a deliberately lean baseline for CGO.
- Go + wazero (
mseedio-wasm): compiled with CGO_ENABLED=0, using the high-level Pack and Parse APIs that copy results into fresh Go-owned slices on every call.
Every run verifies round-trip equality against the 1 Hz sine wave before entering the timed loop. Both Native C and Go + CGO share the same minimal work.h adapter built on msr3_parse and the msr3_pack_init/msr3_pack_next generator:
static int unpack(const char *in, int len, int32_t *out, int cap) {
int used = 0;
while (len > 0) {
MS3Record *r = NULL;
int rc = msr3_parse(in, len, &r, MSF_UNPACKDATA | MSF_ATENDOFFILE, 0);
if (rc || !r || r->reclen <= 0 || r->reclen > len || r->sampletype != 'i' ||
r->numsamples <= 0 || r->numsamples > cap - used) {
msr3_free(&r);
return -1;
}
memcpy(out + used, r->datasamples, r->numsamples * sizeof(*out));
used += r->numsamples;
in += r->reclen;
len -= r->reclen;
msr3_free(&r);
}
return used;
}
static int pack(int version, int32_t *samples, int nsamples, char *out, int cap) {
MS3Record r = MS3Record_INITIALIZER;
strcpy(r.sid, "FDSN:AS_SHAKE_00_E_H_Z");
r.starttime = INT64_C(1786968000000000000);
r.samprate = 100;
r.encoding = DE_STEIM2;
r.formatversion = version;
r.datasamples = samples;
r.sampletype = 'i';
r.samplecnt = r.numsamples = nsamples;
r.datasize = (size_t)nsamples * sizeof(*samples);
MS3RecordPacker *p = msr3_pack_init(&r, MSF_FLUSHDATA | (version == 2 ? MSF_PACKVER2 : 0), 0);
if (!p) return -1;
char *rec;
int32_t len;
int status, used = 0;
while ((status = msr3_pack_next(p, &rec, &len)) > 0) {
if (len <= 0 || len > cap - used) { status = -1; break; }
memcpy(out + used, rec, len);
used += len;
}
msr3_pack_free(&p, NULL);
return status < 0 ? -1 : used;
}
On the CGO side, the bridge passes Go slice backing pointers straight into work.h, while the mseedio-wasm benchmark drives the public Go API:
// CGO/bind.go — one CGO crossing per window, reusing caller buffers
func pack(version int, samples []int32, out []byte) int {
return int(C.pack(
C.int(version),
(*C.int32_t)(unsafe.Pointer(&samples[0])),
C.int(len(samples)),
(*C.char)(unsafe.Pointer(&out[0])),
C.int(len(out)),
))
}
func unpack(in []byte, samples []int32) int {
return int(C.unpack(
(*C.char)(unsafe.Pointer(&in[0])),
C.int(len(in)),
(*C.int32_t)(unsafe.Pointer(&samples[0])),
C.int(len(samples)),
))
}
// minute_test.go — CGO_ENABLED=0 using mseedio-wasm
func BenchmarkMinute(b *testing.B) {
m, sid, start := newInitialized(b)
defer m.Close()
samples := makeSineSamples(6000)
record := mseedio.Record{
SID: sid,
StartTime: start,
SampleRate: 100,
Samples: mseedio.Samples{Type: mseedio.SampleTypeInt32, Int32: samples},
}
for _, v := range []uint8{2, 3} {
opts := &mseedio.PackOptions{FormatVersion: v, Encoding: mseedio.EncodingSteim2}
encoded, err := m.Pack(record, opts)
if err != nil {
b.Fatal(err)
}
b.Run(fmt.Sprintf("Pack/v%d", v), func(b *testing.B) {
for b.Loop() {
if _, err := m.Pack(record, opts); err != nil {
b.Fatal(err)
}
}
})
b.Run(fmt.Sprintf("Parse/v%d", v), func(b *testing.B) {
for b.Loop() {
if _, err := m.Parse(encoded); err != nil {
b.Fatal(err)
}
}
})
}
}
All single-core measurements were run with GOMAXPROCS=1 across 5 independent trials and summarized by median, with -test.benchmem enabled on the Go binaries.
Single-Core Latency, Allocations, and Cold Start

| Operation |
Native C |
Go + CGO |
Go + wazero |
wazero / Native |
wazero Go Allocs |
| Pack v2 |
14.5 µs |
15.2 µs |
67.4 µs |
4.7× |
66.3 KB / 42 |
| Pack v3 |
17.6 µs |
18.2 µs |
71.5 µs |
4.1× |
62.2 KB / 42 |
| Parse v2 |
8.7 µs |
8.2 µs |
44.4 µs |
5.1× |
71.1 KB / 41 |
| Parse v3 |
7.9 µs |
8.3 µs |
42.5 µs |
5.4× |
67.0 KB / 41 |
Native C and Go + CGO land within noise of each other because a single CGO call amortizes cleanly over 6,000 Steim-2 samples. mseedio-wasm pays 4.1–5.4× the latency of native C and allocates 62–71 KB (41–42 allocs) per minute on the Go heap—the direct price of running inside WebAssembly linear memory and copying every output into Go-owned values.
Even with that multiplier, the absolute speed is comfortably fast for waveform pipelines: on a single core, Parse v3 sustains ~23,500 one-minute windows per second (~392 hours of 100 Hz data per second), and Pack v3 sustains ~14,000 windows per second (~233 hours/s).
What you do have to plan around is cold startup. Compiling and instantiating the embedded 339 KiB libmseed.wasm via wazero's optimizing compiler (New + Init + Close, 5 trials × 10 ops) takes a median 207.1 ms (198.2–223.6 ms) and 69.5 MiB / 109,206 allocs. That's roughly 3,000–5,000× slower than a single Pack or Parse, which means MiniSEED should be initialized once at process startup—never inside a request handler.
Scaling Across Window Durations (10s to 1h)
To separate fixed per-call boundary overhead from steady-state Wasm execution, I ran the same miniSEED v3 Steim-2 workload from 10 seconds (1,000 samples) up to 1 hour (360,000 samples):

| Window (samples) |
Op |
Native C |
Go + CGO |
Go + wazero |
wazero Throughput |
wazero / Native |
| 10s (1,000) |
Pack |
2.9 µs |
3.0 µs |
13.7 µs |
73 Msamples/s |
4.7× |
| 1m (6,000) |
Pack |
17.0 µs |
17.6 µs |
70.1 µs |
86 Msamples/s |
4.1× |
| 10m (60,000) |
Pack |
167.3 µs |
173.0 µs |
681.3 µs |
88 Msamples/s |
4.1× |
| 1h (360,000) |
Pack |
1.01 ms |
1.03 ms |
4.18 ms |
86 Msamples/s |
4.1× |
| 10s (1,000) |
Parse |
1.3 µs |
1.3 µs |
8.6 µs |
116 Msamples/s |
6.6× |
| 1m (6,000) |
Parse |
7.7 µs |
7.8 µs |
41.9 µs |
143 Msamples/s |
5.5× |
| 10m (60,000) |
Parse |
77.1 µs |
82.5 µs |
394.4 µs |
152 Msamples/s |
5.1× |
| 1h (360,000) |
Parse |
0.48 ms |
0.50 ms |
2.44 ms |
148 Msamples/s |
5.1× |
On tiny 10-second buffers, fixed guest-allocation and marshaling work pushes Parse to 6.6× native. Once payloads reach a minute or more, that overhead amortizes out and the ratio settles cleanly at 4.1× for Pack (~86–88 Msamples/s) and 5.1× for Parse (~148–152 Msamples/s)—parsing a full hour of 100 Hz waveform data in 2.44 ms.
Concurrency: Shared Instance vs. Instance Pool
Because a single MiniSEED instance guards its Wasm module behind a mutex, sharing one instance across goroutines won't scale across CPU cores. If you need multi-core throughput without CGO, the fix is a small pool of pre-initialized instances (one per worker/core):
// minute_test.go — one pre-initialized MiniSEED instance per core
n := runtime.GOMAXPROCS(0)
pool := make(chan *mseedio.MiniSEED, n)
for range n {
m, _, _ := newInitialized(b)
pool <- m
}
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
m := <-pool
_, err := m.Parse(encoded)
pool <- m
if err != nil {
b.Fatal(err)
}
}
})
Running b.RunParallel with -test.cpu=1,2,4 (5 trials × 5,000 ops on 1-minute miniSEED v3) makes the difference obvious:

| Mode (1-minute miniSEED v3) |
1 core |
2 cores |
4 cores |
| Pack — Go + CGO |
56.9k /s |
110.9k /s (2.0×) |
184.3k /s (3.2×) |
| Pack — Go + wazero (shared) |
14.5k /s |
13.8k /s (0.9×) |
13.7k /s (0.9×) |
| Pack — Go + wazero (1 inst/core) |
14.4k /s |
26.7k /s (1.9×) |
46.2k /s (3.2×) |
| Parse — Go + CGO |
124.7k /s |
247.3k /s (2.0×) |
405.0k /s (3.2×) |
| Parse — Go + wazero (shared) |
24.5k /s |
24.1k /s (1.0×) |
23.7k /s (1.0×) |
| Parse — Go + wazero (1 inst/core) |
24.0k /s |
44.1k /s (1.8×) |
77.6k /s (3.2×) |
A shared MiniSEED stays completely flat under contention, dipping slightly on Pack as goroutines queue on m.mu. Giving each core its own instance restores linear scaling—3.2× on 4 physical cores, matching CGO's own scaling efficiency while staying CGO_ENABLED=0 (at the cost of paying the ~207 ms Init per pooled instance at startup).
What I Traded for CGO_ENABLED=0
This isn't zero-copy, and a shared MiniSEED instance serializes calls to its module. I wouldn't infer native performance from the fact that the same C code is running. What I get in return is quite specific: the application builds without a target C compiler, libmseed still does the format work, and the Go caller doesn't have to remember who owns a C pointer.
If you want to follow one record through the boundary, start with example/parse and then read parseRecordLocked. The example fits on a screen precisely because the pointer bookkeeping doesn't have to.