← All releases

go1.20.0

Major

February 1, 2023

Go 1.20 has no major new language syntax but brings a preview of profile-guided optimization, coverage instrumentation for full binaries, cgo-disabled-by-default builds, multi-error wrapping (errors.Join), and several crypto packages moving to slower but constant-time implementations.

highlights
  • Language: slice-to-array conversion added — [4]byte(x) works directly, extending Go 1.17's slice-to-array-pointer conversion

  • Language: comparable constraint now accepts types that aren't strictly comparable (e.g. interfaces), so generic code can use them as map keys, with runtime panic risk on comparison

  • unsafe package adds SliceData, String, and StringData functions, completing slice/string construction/deconstruction without relying on internal representation

  • Preview profile-guided optimization (PGO): go build -pgo consumes a pprof CPU profile to drive more aggressive inlining, ~3-4% faster generated code

  • New -cover flag for go build adds coverage instrumentation to full programs/binaries (not just unit tests), profiles written via GOCOVERDIR

  • Standard library packages are no longer pre-compiled and shipped in GOROOT/pkg; they're built on demand and cached like any other package, shrinking the distribution

  • CGO_ENABLED now defaults to 0 when no C toolchain is found; net and os/user were rewritten to pure Go on macOS, and the race detector on macOS no longer requires cgo/Xcode

  • errors.Join added and fmt.Errorf/errors.Is/errors.As now support wrapping and inspecting multiple errors via repeated %w verbs

  • New crypto/ecdh package for explicit ECDH key exchange; crypto/ecdsa and crypto/rsa moved to constant-time implementations, causing 5-45% slower operations (RSA encryption ~20x slower)

  • net/http gets ResponseController with SetReadDeadline/SetWriteDeadline; httputil.ReverseProxy adds a Rewrite hook replacing Director for safer request rewriting

  • go build/go test drop the long-deprecated -i flag; go command adds -C to change directory, and go test/go generate add -skip pattern matching

  • Go 1.20 is the last release supporting Windows 7/8/Server 2008/2012 and macOS 10.13/10.14; Go 1.21 will require newer OS versions