Golang previews profile-guided optimization | InfoWorld

0

Go 1.20, a planned upgrade to the Google-developed open source language known for its simplicity, concurrency, and functional programming features, has just reached a release candidate stage. The new version previews profile-guided optimization (PGO) for the compiler.

Announced December 7, the Go 1.20 release candidate can be downloaded from go.dev. The production release of Go 1.20 is expected in February 2023.

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. Version 1.20 uses PGO to more-aggressively inline functions at hot call sites. 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:

  • The runtime adds experimental support for memory-safe arena allocation that makes it possible to eagerly free memory in bulk. This could improve CPU performance.
  • 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 run go test -json do not need updates.
  • The gocode command now defines architecture feature build tags.
  • The go command now disables cgo 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 with go 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 Mojava. 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 © 2022 IDG Communications, Inc.

Leave a Reply