Go release 1.22

Introduction to Go 1.22

Most changes are in the implementation of the toolchain, runtime, and libraries. Maintains the Go 1 promise of compatibility.

Changes to the language

  • For loop variables are now created anew for each iteration to avoid accidental sharing bugs.
  • For loops can now range over integers.

Tools

  • Commands in workspaces can use a vendor directory containing dependencies.
  • go get is no longer supported outside of a module in legacy GOPATH mode.
  • go test -cover now prints coverage summaries for packages without test files.

Runtime

  • Improves CPU performance by 1-3% by keeping type-based GC metadata nearer to heap objects.
  • Reduces memory overhead by approximately 1%.
  • Programs linking or loading Go libraries built with -buildmode=c-archive or -buildmode=c-shared on windows/amd64 can now use SetUnhandledExceptionFilter.

Compiler

  • Profile-guided Optimization (PGO) builds can devirtualize a higher proportion of calls.
  • New heuristics to boost inlinability at call sites deemed important, enabled with GOEXPERIMENT=newinliner.

Linker

  • The -s and -w flags behave more consistently across platforms.
  • On ELF platforms, -B gobuildid generates a GNU build ID derived from the Go build ID.
  • On Windows, -linkmode=internal now preserves SEH information from C object files.

Bootstrap

Requires the final point release of Go 1.20 or later for bootstrap.

Core library

  • New math/rand/v2 package with faster algorithms and improved seeding.
  • New go/version package for validating and comparing Go version strings.
  • Enhanced HTTP routing patterns in the standard library, including method and wildcard support.

Ports

  • On macOS, the Go toolchain now generates position-independent executables (PIE) by default.
  • GOARM environment variable now allows selection of software or hardware floating point.
  • Experimental port to OpenBSD on big-endian 64-bit PowerPC.