Go 1.26 brings more flexible syntax and faster garbage collector
Latest update to programming language enables the Green Tea garbage collector by default, makes generics more flexible, and reduces the overhead of cgo calls.
(Image: The Viz / Shutterstock.com)
The Go team has released version 1.26 of the Go programming language. The release refines the language, enables a new garbage collector by default, and modernizes core tools.
New becomes more expressive, generics usable recursively
The built-in new function now accepts an expression as an operand, meaning a value or expression to which the function is applied. This allows developers to specify an initial value directly when creating a variable and formulate code more compactly. An example of this can be found in the announcement post.
Additionally, generic types can now refer to themselves within their type parameter list. This simplifies the implementation of more complex data structures and interfaces.
Videos by heise
Green Tea GC now standard
The previously experimental “Green Tea” garbage collector (GC) is now enabled by default in Go 1.26. After a testing phase in Go 1.25 and based on the feedback collected, the team is now moving it to regular operation.
The revised GC design is intended to particularly improve the marking and scanning of small objects, among other things, through better memory locality and higher CPU scalability. Depending on the application, the Go team reports potential reductions in GC overhead in the range of approximately 10 to 40 percent, mainly for programs with intensive memory cleanup.
Those who do not wish to use the new collector can disable it during the build via GOEXPERIMENT=nogreenteagc. This opt-out option is set to be removed with Go 1.27.
Runtime and compiler optimize memory management
According to the Go team, Go 1.26 reduces the base overhead of cgo calls by about 30 percent. Programs that frequently switch between Go and C code could benefit from this, as each transition incurs less runtime cost. Additionally, on 64-bit systems, the runtime randomizes the base address of the heap upon startup. This makes it more difficult to predict memory addresses and is primarily intended to increase resilience against certain attack scenarios, especially in combination with cgo.
The compiler also plays a greater role in memory optimization: it can place the backing store of slices on the stack instead of the heap in more cases, which reduces allocations and can improve performance. If problems occur, the bisect tool and the flag -compile=variablemake can be used to pinpoint the cause. The new stack allocations can be completely disabled using -gcflags=all=-d=variablemakehash=n.
go fix as a modernizer
The development team has reimplemented the go fix command based on the Go Analysis framework. It includes numerous modernizers that suggest safe adjustments to newer language and library features. A new inline analyzer considers functions with the directive //go:fix inline.
Also new are the packages crypto/hpke, crypto/mlkem/mlkemtest, and testing/cryptotest. Experimentally available are, among others, simd/archsimd, runtime/secret, and a goroutineleak profile in runtime/pprof.
Further information can be found in the Release Notes for Go 1.26.
(mdo)