Go release 1.21

Introduction to Go 1.21

Go 1.21 introduces a change in the numbering of releases. The first release is now Go 1.N.0.

The release maintains Go 1 compatibility promise, expecting almost all programs to continue to compile and run as before.

Changes to the language

  • New functions min and max to compute smallest or largest value.
  • New function clear to delete elements from a map or zero elements of a slice.
  • Precise package initialization order specified.
  • Multiple improvements in type inference.

Preview of per-iteration for loop variables.

Changes in goroutine panic and recover behavior.

Tools

Formalization of GODEBUG environment variable for backward compatibility.

Strict minimum requirement for Go version in go.work or go.mod file.

Ability for go command to invoke other Go toolchain versions.

Runtime

  • Improved stack printing for very deep stacks.
  • Better memory management for Linux platforms supporting transparent huge pages.
  • Up to 40% reduction in application tail latency due to garbage collection tuning.
  • Significant reduction in overhead for C to Go calls on Unix platforms.

Compiler

Profile-guide optimization (PGO) ready for general use, with performance improvements of 2-7%.

Improved build speed by up to 6%.

Core library

  • New log/slog package for structured logging with levels.
  • New slices package for common operations on slices.
  • New maps package for common operations on maps.
  • New cmp package for ordered type comparisons.

Ports

  • Go 1.21 requires macOS 10.15 Catalina or later.
  • Go 1.21 requires at least Windows 10 or Windows Server 2016.
  • New go:wasmimport directive for WebAssembly.
  • Experimental port to WebAssembly System Interface (WASI).