← All releases

go1.21.0

Major

August 8, 2023

Go 1.21 adds min/max/clear builtins, much stronger generics type inference, and a formally defined package init order, while overhauling toolchain handling so go.mod's go line is a strict minimum and GODEBUG preserves old behavior on upgrade. It also ships log/slog, slices, maps, and cmp packages, production-ready PGO, and notable GC latency improvements.

highlights
  • New builtin functions min, max, and clear for computing extremes and clearing maps/slices

  • Package initialization order is now precisely specified by an explicit algorithm based on the import graph

  • Generic type inference is substantially more powerful: works with generic function arguments, interface assignment via methods, and untyped constant mixing, while also catching more inference errors

  • Preview of per-iteration (rather than per-loop) for-loop variables available via an opt-in experiment, not the default

  • panic(nil) now produces a *runtime.PanicNilError so recover() after a direct deferred call is guaranteed non-nil; old behavior restorable with GODEBUG=panicnil=1

  • go.mod/go.work 'go' line is now a strict minimum Go version requirement, and the go command can auto-download/invoke a newer toolchain to satisfy it; new 'toolchain' directive added

  • GODEBUG settings are now tied to the module's go line, letting upgraded toolchains preserve old behavior for backwards compatibility

  • New standard library packages: log/slog (structured logging), slices, maps, cmp, and testing/slogtest

  • Profile-guided optimization (PGO) is now production-ready and auto-enabled via a default.pgo file, giving roughly 2-7% performance gains; build speed also improved up to 6%

  • Runtime GC tuning can cut application tail latency up to 40%, and Linux huge-page handling was improved for better memory/CPU tradeoffs

  • crypto/elliptic Curve methods are deprecated in favor of crypto/ecdh; crypto/tls gains custom session ticket control; ECDSA/RSA Equal methods now run in constant time

  • Go 1.21 requires macOS 10.15+ and Windows 10+, and adds an experimental WebAssembly System Interface port (GOOS=wasip1) plus new sync.OnceFunc/OnceValue/OnceValues helpers