TECHNOLOGY

Goose, a new memory-safe systems language, claims faster speeds than C++ and Rust with no heap or garbage collector

Goose is a new programming language that keeps all dynamic data on compiler-managed stacks instead of a heap. Its authors report it beats C++ and safe Rust on speed and memory across 16 of their own benchmarks.

Developer's monitor showing source code in a code editor beside a terminal compiling a program, on a desk in daylightTECHNOLOGY

Image: goose

Goose is a new systems programming language that has no heap, no garbage collector and no lifetime annotations, yet is designed to be memory safe. Its project page says that across sixteen benchmarks it runs about 3.3x faster than idiomatic C++, 1.16x faster than hand-optimized C++ and 1.12x faster than the best safe Rust. These are the project's own benchmark results.

The core idea is simple. In most languages, a program asks a memory manager (the heap) for space as it goes. Goose skips that. Every dynamic value lives inline on a data stack the compiler manages. Growing a value moves a pointer forward, and memory is freed when its scope ends. The compiler works out how many such stacks a program needs and proves at compile time that the layout is safe.

The syntax will look familiar to C and Rust programmers. According to the project, a reference into a growing array stays valid however much the array grows, because nothing moves. In C++, a vector may reallocate and break such references. Goose also needs no lifetime syntax. The compiler works out what each reference points into and rejects any reference that could outlive its owner. When that check fails, the error names the reference's root and its destination.

Nested data stays inline too. A string, an array of strings, or a record with variable-size fields is stored as one contiguous block with no pointers inside. The project gives an example: an order record with a customer name and two line items takes 29 bytes and no allocations in Goose. As C++ std::string plus std::vector it takes 160 bytes and one allocation. In Rust it takes 153 bytes and four allocations.

Enums get similar treatment. In Goose's variable mode, each value takes only the size of its own variant, not the size of the largest one. The project says this gave 4x less memory and 2x the speed of a Rust enum on the benchmark that exercises it.

The language also changes how some everyday tasks work. A relative reference can store a link as a 1, 2 or 4-byte offset instead of an eight-byte address. Because such structures do not depend on where they sit in memory, saving one is a write and loading is a read plus a check. That check rejects corrupt or hostile bytes. Errors can be returned from several calls up with a statically checked return, with no Result type. Threads share nothing: each worker is compiled as its own program, and flat values pass between them through typed queues as a memory copy.

On the numbers, the project reports a geometric mean over 16 benchmarks. With the MSVC backend, Goose is 3.51x faster than idiomatic C++, 1.24x faster than hand-optimized C++ and 1.13x faster than the best safe Rust. With the clang backend the figures are 3.54x, 1.26x and 1.19x. Peak memory is 1.95x, 1.32x and 1.25x lower. Measurements use whole-process wall-clock time, including teardown. The page says the benchmarks include losses as well as wins, and the full results are in the repository.

The project is open about the costs. Programmers must think about where data lives and who owns it. Recursive functions cannot keep growable data across a recursive call. Arrays of variable-size elements can be iterated but not indexed. There are no escaping closures, no function pointers, and compilation is whole-program only. If a slot returned to a reusable pool is still used, it reads whatever its next owner put there. The project calls that a logic bug, never memory corruption.

Goose compiles to a single C file, so it runs wherever a C compiler does and can call C code directly. A bundled TinyCC backend can compile and run a program in-process. Prebuilt compilers are available for Windows (x64), Linux (x64) and macOS (Apple silicon and Intel). The repository also has a tutorial, a reference, a specification, thirty-one sample programs and a VS Code extension.

It is a whole-program compiler of about thirty thousand lines of C++, with a specification, a standard library and a test suite that runs in CI on Windows, macOS and Linux. Some features are deliberately out of scope for now, including moves for resizable values and labeled break. Goose is licensed under Apache 2.0. Wouter van Oortmerssen is credited with language and compiler design, and Claude Fable with compiler implementation, benchmarking, and sample and doc writing.

Sources and further readingThe Goose Programming Language · Goose ↗
ABOUT THE DESK

Harsh DV

IntraGoals reports on important changes in technology and work. We check each story for clear writing, trusted sources and useful information before it is published.

KEEP READING

Latest from IntraGoals.

All latest stories ↗