NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
▲TinyGo 0.45.0 (github.com)
neomantra 5 hours ago [-]
I was a drive-by contributor to TinyGo, focused on getting MacOS and JS/WASM working well this summer, along with getting BubbleTea to work with it (the last of which was finally merged yesterday!). It was a lot of work, but now it unlocked so much capability for me.

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

noselasd 4 hours ago [-]
Out of curiosity, what can and can't TinyGo do that the official Go compiler/runtime can do ?
32 minutes ago [-]
wkjagt 4 hours ago [-]
The goal is to run on very limited resources, like micro controllers (ie ESP32, Arduino)
justinclift 3 hours ago [-]
It compiles to much smaller sized executables, which in some environments is very important. ie webassembly, embedded devices
theplumber 2 hours ago [-]
does WASM actually work in browser?

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

aaron42net 1 hours ago [-]
I used tinygo v0.4.1's WASM support in a multi-player browser game (https://smiloid.net) where I wanted to run the world simulation and drone logic to be shared between the browser and the server. In single-player, everything runs in the browser via WASM. In multi-player, the server maintains the authoritative copy and the client renders it predictively based on its user's inputs (modern game netcode style). The rendering engine is in the tinygo WASM, too, which dumps out trapezoids, circles, etc for the browser to draw.

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.

donatj 6 hours ago [-]
Very nice! I have really been enjoying TinyGo for a couple Pi Pico projects I've been toying with.

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.

K0IN 5 hours ago [-]
Sorry, I did not use tiny go yet (it's on my bucket list for a long time), i thought it's compatible with go, why would you need a differentiation?
gen2brain 6 hours ago [-]
That is usually done with the build tags, for different OSes and arches, and TinyGo defines the tinygo build tag.
worg 1 hours ago [-]
^ this, and if you really really wanted to have visual differentiation within files nothing prevents you to combine the build tag with a "compound extension" like `.tiny.go`
onlyrealcuzzo 3 hours ago [-]
This seems pretty cool, but I can't gather from the README what it does and does not do:

``` 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.

rob74 3 hours ago [-]
The "non-goals" section probably makes more sense if you read the "goals" section first, which boils down to "very small binary sizes, support for µcontrollers and WebAssembly, CGo support, be able to compile most Go code without modifications". The "non-goals" then basically say that they have to make some compromises to achieve the goals.
onlyrealcuzzo 1 hours ago [-]
No - it still doesn't.

I get what it wants to do.

I have no idea what that costs.

mkarliner 4 hours ago [-]
I've working on MicroPython with my project thingstudio.net (sorry for plug) and the biggest issue I've had is memory fragmentation, especially on ESP32's. Does anyone have an insight/comparison on Go garbage collection vs Python?
dofm 9 hours ago [-]
Part of my LLM-and-agentic-learning phase is giving up interpreted web dev languages and forcing myself to develop agentic skills by using a language I am less familiar with.

I have some Go experience (a small utility used by some dozens of quite niche customers) and trivial experience of macOS development.

So far my two projects have been Go/Gin/goose etc. — a web app — and a small desktop Swift app. But there's GUI stuff for Go and web stuff for Swift. (I could have written my mac app exactly in Golang because there's a package that does what I need)

I had hoped I would find that one of these languages was clearly better than the other. Go is obviously better for the LLM, maybe a bit tiresome to see enormous reams of it for me. Swift is a little harder on the LLM (and it builds more slowly) but it's a bit easier on the eye; I've been very productive in it.

Here, again, it will be hard to separate TinyGo and Embedded Swift.

And there's WASM support for both.

shim__ 5 hours ago [-]
Swift has no garbage collector(just reference counting) as opposed to Go, which should make it a better fit for microcontrollers, since the runtime is lighter
pjmlp 58 minutes ago [-]
Reference counting is a garbage collection algorithm.

Chapter 5, https://gchandbook.org

"A Unified Theory of Garbage Collection"

https://web.eecs.umich.edu/~weimerw/2012-4610/reading/bacon-...

9 hours ago [-]
KingOfCoders 12 hours ago [-]
I'm using it to generate WASM, sadly Go with the GC/goroutine infra is not as good a WASM language than e.g. Rust which is a very simple 'binary', TinyGo works well though.
rcarmo 9 hours ago [-]
Yep. I use it on https://github.com/rcarmo/go-rdp for my RDP web client.
logicallee 11 hours ago [-]
Could I ask how you do that? How do you actually build with a webassembly target? I might be interested.
wffurr 9 hours ago [-]
From the TinyGo docs, it’s as simple as

    GOOS=js GOARCH=wasm tinygo build -o wasm.wasm ./main.go
https://tinygo.org/docs/guides/webassembly/wasm/

It relies on LLVM’s Wasm backend and some JS glue libraries for the browser.

KingOfCoders 11 hours ago [-]
childintime 8 hours ago [-]
Appreciated.
logicallee 11 hours ago [-]
that's really interesting, thank you. I'm not sure we're ready to use that platform, though :)
KingOfCoders 10 hours ago [-]
Many aren't, it's a big ask. But I'm more interested in spreading the idea than selling something. I found WASM an underrated gem - e.g. https://pglite.dev/
mrtimo 9 hours ago [-]
Agreed. DuckDB wasm is amazing. [1]

[1] https://github.com/duckdb/duckdb-wasm

KingOfCoders 4 hours ago [-]
It is!
01HNNWZ0MV43FF 11 hours ago [-]
So you want to take arbitrary code in arbitrary languages, and run it on someone else's computer inside a sandbox?

Yes, wasm can do that.

You can compile the code to wasm, then run it in a runtime like wasmer or wasmtime. Or you can ahead-of-time compile it with something like wasm2c, which generates C code.

actionfromafar 9 hours ago [-]
w2c2 is also very good
ncruces 5 hours ago [-]
Or (shameless plug) if you want to generate Go from Wasm: https://github.com/ncruces/wasm2go
nottorp 3 hours ago [-]
You can even compile your C code to wasm and then compile that to C with wasm2c can't you?
kermatt 2 hours ago [-]
> Go compiler for ... command-line tools.

Is there a case for building CLIs with TinyGo meant to run on workstations, instead of the vanilla Go compiler?

shit_game 10 hours ago [-]
TinyGo has been my favorite means of using my Raspi Picos so far. My only gripe so far is that maps are nigh unusable due to their slowness, but this is generally simple enough to work around (at the expense of performance). I'm sure there are still more rough edges, but I don't think I'm experienced enough with embedded software to identify them.
ghoul2 6 hours ago [-]
awesome. I love tinygo - these days mainly to be able to 'dual serve' my go services as cloudflare workers via the tinygo wasm target. works beautifully.
pjmlp 9 hours ago [-]
Lots of goodies in the release.

Congratulations to the team.

Are some of the improvements coming from TamaGo? I know there was supposed to exist a collaboration with other Go toolchains, if I remember correctly a issue that I saw fly by in the past.

Conol_ai 10 hours ago [-]
[dead]
CylVolumeCalc 11 hours ago [-]
[dead]
Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 16:31:46 GMT+0000 (Coordinated Universal Time) with Vercel.