Railink background: writing a game in Go

submited by
Style Pass
2024-07-04 13:00:07

Our colorful strategy/puzzle game Railink started as a little 3D demo project in Go. From there it kind of grew, and things kept being being added until it was so close to being a real game that it might as well be finished and released. That happened, and it is available on Steam!

The Go garbage collector is very low latency. And it's true that Railink does not seem to suffer from frame drops, even on slow hardware. However, on the other side the GC also does not seem to free that much. This means you have to be mindful of allocations.

In Go, there is the typical NewSomeInstance() function pattern that returns a pointer (like bytes.NewBuffer). This pattern is used everywhere in Go libraries, but the downside is that it causes allocations. Allocations are slow and it can be difficult to get the memory back. Just returning the struct instead of a pointer seems to be much faster in practise. This is an important lesson for writing fast Go code.

Also, whenever a struct gets converted into an interface, like with fmt.Println which takes any arguments, an allocation happens. It helps to try and avoid this, or otherwise try to reuse the interface.

Leave a Comment