Go 1.20, an upgrade to the Google-developed open source language known for its simplicity, concurrency, and functional programming features, has arrived in a production release. The new version previews profile-guided optimization (PGO) for the compiler.
Announced February 1, Go 1.20 can be downloaded from go.dev. With Go 1.20, preview support for PGO enables the compiler toolchain to perform application-specific and workload-specific optimizations based on runtime profile data. The compiler currently supports pprof CPU profiles, which can be collected through the runtime/pprof
or net/http/pprof
packages.
Also known as feedback-directed optimization, PGO feeds information (a profile) from representative runs of the application back to the compiler for the next build of the application, which uses that information to make more informed optimization decisions. Benchmarks for a representative set of Go programs show enabling PGO inlining optimization improves performance about 3% to 4%. More PGO optimizations are planned for future releases.
Go 1.20 also introduces four changes to the language. First, an improvement made in 2021’s Go 1.17 release—the ability to convert a slice to an array pointer—has been extended to allow conversions from a slice to an array, according to draft release notes.
Second, the unsafe
package defines three new functions: SliceData
, String
, and StringData
. These functions provide the complete ability to construct and deconstruct slice and string values without depending on exact representation.
Third, the specification now defines that struct values are compared one field at a time, considering fields in the order they appear in the struct type definition and stopping at the first mismatch. And fourth, comparable types such as ordinary interfaces now may satisfy comparable constraints, even if the type arguments are not strictly comparable. This enables instantiation of a type parameter constrained by comparable
with a non-strictly comparable type argument such as an interface type, or a composite type containing an interface type.
Also with Go 1.20:
- Collection of code coverage profiles for programs is supported, including for applications and integration tests, as opposed to just unit tests.
- The directory
$GOROOT/pkg
no longer stores precompiled package activities for the standard library. Instead, packages in the library are built as needed and cached in the build cache. This reduces the size of the Go distribution and avoids C toolchain skew for packages that use cgo. - The implementation of
go test –json
has been improved to be more robust. Programs that rungo test -json
do not need updates. - The
go
command now defines architecture feature build tags. - The
go
command now disablescgo
by default on systems without a C toolchain. - The
go version -m
command now supports reading more types of Go binaries, most notably Windows DLLs built withgo build- buildmode=c shared
and Linux binaries without execute permission. - Experimental support is added for FreeBSD on RISC-V.
- Go 1.20 is the last release that will run macOS 10.13 High Sierra or 10.14 Mojave. Go 1.21 will need macOS 10.15 Catalina or later.
Go 1.19, which improved generics and the memory model, was released August 2.
Copyright © 2023 IDG Communications, Inc.