wasm2go: a Wasm to Go translator

12 views
Skip to first unread message

Nuno Cruces

unread,
Mar 14, 2026, 7:37:55 PM (6 hours ago) Mar 14
to golang-nuts
For the past few weeks I've been working on a Wasm to Go translator. It takes a Wasm module and converts it to a Go package. I plan to use it for my SQLite driver. I'm translating a Wasm build of SQLite into ~ 600 kLoC of Go. I've tested it across 20 GOOS/GOARCH combinations.

I have found that GC produces suboptimal code in some situations.

Wasm is a little endian platform, so a memory load is something like (offset is a constant literal):

int32(binary.LittleEndian.Uint32(m.Memory[int64(ptr)+offset:]))

I've noticed that, on little endian platforms, this works much faster:

*(*int32)(unsafe.Pointer((*[4]byte)(m.Memory[int64(ptr)+offset:])))

I think because the first version has 2 bounds checks, and the later just one? This is unfortunate, as I have to generate 2 versions of the code (for little and big endian).

Am I missing any trick to get the compiler to generate better code?

Thanks! 
Reply all
Reply to author
Forward
0 new messages