49 comments
The TinyGo project is an intensely talented cadre of developers. They care deeply this alternative Go compiler/runtime. It was really neat to see them in action and how an already established project accelerated in a year.
It was interesting to see how they adopted LLMs (basically use them but you better know what's going on) and how they dealt with newcomers. The project's scaffolding has improved to keep pace.
While it was intended to get Golang on small devices, the same love makes it work well for WASM. Also it improves as LLVM improves.
I rather consistently get 50% size binaries that run 10% faster and use lower memory than Vanilla Go. The drawback is 5x slower build times. So I dev-loop with Vanilla go and then prod-loop with TinyGo.
Booba will help you embed your Golang in a browser, either Vanilla or TinyGo. There's still some go.mod friction, but the next BubbleTea release will fix that.
https://nimbleterminal.com/booba
Here's some TinyGo interactive graphics next to Vanilla:
https://nimblemarkets.github.io/ntcharts3d/?demo=gallery&com...
Pro-tip: use gc=boehm for JS/WASM targets
I know that in the standard Go compiler it is still “experimental”. What I mean by that is the program can hang due various issues with wind/unwind browser behaviour. The memory management seems to be another issue. You just can’t ship go-> wasm app in browser in production.
My hope is that once wasi 3 and a wasm-gc implementation will be released for Go then I will finally be able to actually use Go in the browser(via WASM). Until then it’s more or less a kind of java applets experience
To get the size down, I avoided including anything using reflection (including encoding/json and fmt) and left most of the runtime out, which means the WASM blob can't do concurrency or its own scheduling. The WASM blob is used basically as a set of function calls that take some input and return some output via a preallocated byte buffer shared between TypeScript and Go, with all of the timing, etc driven by the TS side.
This was a weird set of design tradeoffs, but the result is that thousands of lines of Go turn into 276k uncompressed (128k compressed) WASM blob that has 118k of minified JS (37k compressed) driving it that works pretty well. And I still got to make heavy use of Go's great fuzzing tools to chase down weird bugs in the drone logic.
Compared to "hello world" in normal Go being a few megabytes, this seemed pretty impressive, but you could certainly use more of the Go runtime and standard library if you weren't trying to optimize size as much.
I wrote a CP/M emulator, and only had to make trivial changes to compile it to WASM and run it in a browser with xterm.js. (Mostly relating to abstracting the filesystem, and adding a plugin for console I/O.)
No threading is involved, and nothing complex, but it does allow you to run turbo pascal, zork, etc, etc.
taa! :trophy:
Way saner than the C pico projects I've helped my friend work on.
Maybe it's just me but I kind of wish there was more of a way to clearly differentiate a Go project from a Tiny Go project, like .tgo file extensions or like a "compiler tinygo" directive in go.mod or something.
``` Non-goals:
* Be efficient while using zillions of goroutines. However, good goroutine support is certainly a goal.
* Be as fast as gc. However, LLVM will probably be better at optimizing certain things so TinyGo might actually turn out to be faster for number crunching.
* Be able to compile every Go program out there.
```
This could mean almost literally anything from - practically - it doesn't compile any existing commonly used Go packages, and is worse at concurrency than Java to it will compile almost anything except packages that are doing really weird, generally accepted terrible things and outside of rare p999 edge cases, it's competitive with Go.
I get what it wants to do.
I have no idea what that costs.
Read the full thread on Hacker News →
Related stories
- Hacker News · 1 points · 3 days ago
- Show HN: Timeline of the Far Futurerivendell.dmitrybrant.comHacker News · 16 points · 2 months ago
- Hacker News · 1 points · 2 months ago
- Show HN: Analysis of Hacker News predictions since 2008hnpredictions.comHacker News · 125 points · 8 days ago
- The Verge · 0 points · 5 days ago
- Record-Low 31% Say College Education Is 'Important'news.gallup.comHacker News · 4 points · 2 months ago