gd compiler
A fork of the Go compiler that aggressively allocates on the stack — less GC pressure for real-time graphics, and carefully written programs that can run with the GC turned off.
What's different
- Fat interfaces. Interfaces carry 16 bytes of inline storage, so strings, slices and any numeric type are stored directly instead of allocated.
- Small strings. Up to 15 bytes live in the string header itself; heap strings use the spare word for a cached hash.
- Escape analysis across dynamic dispatch. Each closure and method carries which of its arguments escape, so the caller keeps arguments on the stack when the actual callee doesn't leak them.
- Pointer results on the caller's stack. A function returning
*Twrites into a buffer the caller provides when the result doesn't escape. - One binary. The
gocommand embeds the standard library andasm,cgo,compileandlink.
Fewer allocations, measured
| benchmark | ns/op stock | ns/op gd | allocs |
|---|---|---|---|
| closure, argument not escaping | 11.21 | 4.22 | 1 → 0 |
| interface method, argument not escaping | 11.37 | 4.57 | 1 → 0 |
| callback dispatch | 11.61 | 3.98 | 1 → 0 |
fmt.Sprintf("%s") | 7.49 | 5.41 | 1 → 0 |
fmt.Sprintf with a Stringer | 29.97 | 20.57 | 3 → 0 |
Not everything gets faster: larger interfaces and strings mean more bytes to copy, and some benchmarks (for example encoding/json decoding) are slower. The full results are in doc/gd.
Does it work?
all.bashpasses onamd64; the standard library tests pass onarm64andjs/wasm.- On
js/wasmeach goroutine runs on its own WebAssembly stack (JavaScript Promise Integration: Chrome 137, Firefox 153, Safari 27, Node.js 24), and functions use structured control flow instead of a dispatch loop. - In development: a WebAssembly GC target (
GOWASM=gc), which already passes the Go spec tests and the standard library's own tests.
Try it
git clone https://github.com/quaadgras/compiler.gd
cd compiler.gd/src && ./make.bash
export PATH=$PWD/../bin:$PATH
go version
The ABI differs from stock Go (wider interfaces and strings), so assembly and code that relies on unsafe layouts of those types needs care.
How it's built
The high-level design is directed by a person with a deep knowledge of the language; the implementation work is done by an LLM. That makes it practical to explore compiler trade-offs that wouldn't otherwise get the time and attention. Changes go through the Go test suite on every step.