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.

−59%time for calls through closures and interfaces, 1 allocation → 0 (geomean of the escape-bits benchmarks)
16 Binline storage in every interface: strings, slices and numbers never box
15 Bstrings stored inline, no heap pointer

What's different

  1. Fat interfaces. Interfaces carry 16 bytes of inline storage, so strings, slices and any numeric type are stored directly instead of allocated.
  2. Small strings. Up to 15 bytes live in the string header itself; heap strings use the spare word for a cached hash.
  3. 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.
  4. Pointer results on the caller's stack. A function returning *T writes into a buffer the caller provides when the result doesn't escape.
  5. One binary. The go command embeds the standard library and asm, cgo, compile and link.

Fewer allocations, measured

benchmarkns/op stockns/op gdallocs
closure, argument not escaping11.214.221 → 0
interface method, argument not escaping11.374.571 → 0
callback dispatch11.613.981 → 0
fmt.Sprintf("%s")7.495.411 → 0
fmt.Sprintf with a Stringer29.9720.573 → 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?

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.