Go 1.19 (2022-08-02)
Go 1.19 was released in August 2022, mainly refining generics support, improving doc comments, and introducing important memory management features.
Major Changes
Language
- Memory Model: Updated the Go memory model documentation to clarify the behavior of atomic operations, aligning with the memory models of C++20, Java, Rust, etc. Go only provides sequentially consistent atomic operations.
- Generics: Fixed some bugs and limitations related to generics found in Go 1.18. Made a minor correction to the scope of type parameters in method declarations.
Toolchain
-
Doc Comments: Supports richer doc comment formats, including headings, lists, and links.
gofmtnow reformats doc comments.// Package json implements encoding and decoding of JSON as defined in
// [RFC 7159]. -
Build Constraints: Added the
unixbuild constraint, which is satisfied whenGOOSis a Unix-like system (such as linux, darwin, freebsd, etc.). -
Go Command: Build information injected by
go buildnow includes the-trimpathflag (if set).
Runtime
- GC Soft Memory Limit: Introduced the
GOMEMLIMITenvironment variable andruntime/debug.SetMemoryLimitfunction, allowing a soft memory limit to be set. This helps the GC better utilize available memory and avoid OOM, especially in container environments. - Dynamic Stack Sizing: Improved the initial stack sizing strategy for goroutines, allocating based on historical average usage to reduce stack copying and expansion overhead.
- File Descriptor Limit: On Unix systems, importing the
ospackage automatically raises the soft limit on open file descriptors to the maximum of the hard limit.
Standard Library
sync/atomic: Added typed atomic types (Bool,Int32,Int64,Uint32,Uint64,Uintptr,Pointer), making them more convenient and safe to use, avoiding manualunsafe.Pointerconversions.net/url: IntroducedJoinPathfunction andURL.JoinPathmethod for safely joining URL paths.os/exec:CommandandLookPathno longer look for executables in the current directory by default (for security). AddedCmd.Environmethod.sort: Sorting algorithm rewritten to pattern-defeating quicksort, which is faster in many scenarios. AddedFindfunction.time: AddedDuration.Absto get the absolute value, andTime.ZoneBoundsto get the time zone bounds.fmt: AddedAppend,Appendf,Appendlnfunctions to append formatted data to a byte slice.flag: AddedTextVarfunction, allowing flags to bind to custom types implementing theencoding.TextUnmarshalerinterface.
Platform Support
- LoongArch: Added support for LoongArch 64-bit (
linux/loong64). - RISC-V: The
riscv64port now supports passing function arguments and results via registers, improving performance by about 10%.
References
For more details, please refer to the official release notes: Go 1.19 Release Notes