Go 1 21

Overview

Go 1.21, released in August 2023, makes Profile-Guided Optimization production-ready and introduces commonly requested built-in functions. This release focuses on performance and developer experience improvements.

Key Features

Production-Ready PGO

Profile-Guided Optimization delivers 2-7% performance improvement:

# Collect profile
curl -o cpu.prof http://localhost:6060/debug/pprof/profile?seconds=30

# Place profile
cp cpu.prof cmd/myapp/default.pgo

# Build (PGO automatically enabled)
go build ./cmd/myapp

New Built-in Functions

min and max:

a := min(1, 2, 3)      // 1
b := max(5.5, 2.3)     // 5.5
c := min("apple", "banana")  // "apple"

clear:

// Clear map
m := map[string]int{"a": 1, "b": 2}
clear(m)  // Efficient removal of all entries

// Zero slice elements
s := []int{1, 2, 3}
clear(s)  // [0 0 0]

Improved Type Inference

Better handling of untyped constants with generics:

func Max[T constraints.Ordered](a, b T) T {
    if a > b {
        return a
    }
    return b
}

// Go 1.21: Works naturally
result := Max(0, 1.5)  // T=float64 (inferred)

Go Toolchain Management

Specify Go version requirements in go.mod:

module example.com/myapp

go 1.21
toolchain go1.21.5  // Specific toolchain version

Automatically downloads required toolchains if needed.

References


Last Updated: 2026-02-04 Go Version: 1.21+ (baseline), 1.25.x (latest stable)

Last updated