Go 1.21 officially released

Go 1.21 has been officially released .

Most of the changes in this release focus on the toolchain, runtime, and library implementations. As usual, this release maintains the Go 1 compatibility promise; in fact, Go 1.21 improves on that promise. The development team expects that almost all Go programs will continue to compile and run as before.

Additionally, Go 1.21 introduces a small change to the version numbering.

Go 1.N has been used in the past to refer to entire Go language versions and release series, as well as the first release in the series. Starting with Go 1.21, the first release is now Go 1.N.0 . The latest release is the Go 1.21 language and its initial implementation, the Go 1.21.0 release.

Tools like  go version this will display the version number as " go1.21.0". See "Go versions " in the "Go Toolchains" documentation for details on the new version numbers.

Download address: https://go.dev/dl/


Improved toolchain

  • The Profile Guided Optimization (PGO) feature is officially GA .

The Enable Profile Guided Optimization (PGO) feature that was in preview in 1.20 is now officially GA. If there is default.pgoa file named in the main package directory, gothe command will use it to enable PGO builds.

Profile-guided optimization (PGO) is a compiler optimization technique in computer programming, which translates to optimization guided by configuration files.

PGO is also known as:

  • Profile-directed feedback (PDF)

  • Feedback-directed optimization (FDO)

Its principle is that the compiler uses the runtime profiling information of the program to generate higher-quality code, thereby improving the performance of the program.

As a general compiler optimization technique, PGO is not limited to a certain language. For example,  the Rust compiler is also exploring the use of PGO , and Microsoft uses LTO+PGO to optimize the Linux kernel .

In Go, the original proposal for PGO proposed adding support for Profile-Guided Optimization (PGO) to the Go GC toolchain, so that the toolchain could perform application- and workload-specific optimizations based on runtime information.

The Go development team tested the impact of PGO on various Go programs and found performance improvements of 2-7% .

See the PGO documentation for more details .

language change

  • Added new built-in functions: min, max  and  clear
  • Made several improvements to type inference for generic functions, including extending and clarifying the description of type inference in the spec
  • In future releases, the development team plans to address one of the most common problems in Go programming: loop variable capture . Go 1.21 comes with a preview of this feature, which can now be enabled in code using an environment variable.
    Click here to view details

Add new standard library

  • log/slog package: for structured logging

  • slices package: added for common operations on slices of any element type, this package is faster and more ergonomic than the sort package

  • maps package: for common operations on any type of key-value

  • cmp package: for comparing ordered values

optimize performance

In addition to performance improvements when PGO is enabled:

  • The Go compiler itself has been rebuilt in 1.21 with PGO enabled, so it builds Go programs 2-4% faster, depending on the host architecture
  • Tail latency may be reduced by up to 40% for some applications due to garbage collector tuning
  • Collecting traces with runtime/trace now   incurs much less CPU overhead on amd64 and arm64

Support for WASI

Go 1.21 has experimental support for  WebAssembly System Interface (WASI) , Preview 1 ( GOOS=wasip1, GOARCH=wasm).

To facilitate writing more general WebAssembly (WASM) code, the compiler also supports a new directive to import functions from the WASM host:  go:wasmimport .

See the release notes for details .

further reading

Guess you like

Origin www.oschina.net/news/252970/go-1-21-released