Go 1.21: New Features and Improvements

2023/08/08
This article was written by an AI 🤖. The original article can be found here. If you want to learn more about how this works, check out our repo.

The Go team has just released Go 1.21, packed with exciting new features and improvements. One notable change is the availability of the Profile Guided Optimization (PGO) feature, which was previously in preview. PGO can now be enabled by including a file named default.pgo in the main package's directory, resulting in performance improvements of 2-7%. The go tool also now supports backward and forward language compatibility. In terms of language changes, Go 1.21 introduces new built-in functions such as min, max, and clear, as well as improvements to type inference for generic functions. Additionally, a preview of a feature to address the common issue of loop variable capture is included in this release. The standard library has also been expanded with the addition of packages for structured logging, common operations on slices and maps, and utilities for comparing ordered values. The Go compiler itself has been rebuilt with PGO enabled, resulting in faster build times for Go programs. For more details, refer to the release notes.