Go 1.17 (2021-08-16)
Go 1.17 was released in August 2021, bringing compiler performance improvements, pruned module graphs, and new build tag syntax.
Major Changes
Language
-
Slice Conversion: Support for converting slices to array pointers. If the slice length is less than the array length, the conversion panics at runtime.
s := []int{1, 2, 3}
p := (*[3]int)(s) -
unsafePackage: Addedunsafe.Addandunsafe.Slicefunctions, simplifying pointer arithmetic and slice creation, making code more compliant withunsafe.Pointersafety rules.
Toolchain
-
Pruned Module Graphs: If a module specifies
go 1.17or higher, the module graph includes only the direct dependencies of othergo 1.17modules, no longer loading the full transitive dependency graph. This significantly improves module loading speed for large projects. -
//go:buildSyntax: Introduced the new build tag syntax//go:build, replacing the old// +build, supporting boolean expressions and being more readable.//go:build linux || darwin -
go getDeprecation: The feature ofgo getto install executables is deprecated (and will be removed in a future version); usego install cmd@versioninstead.
Performance
- Register-based Calling Convention: On x86-64 (amd64) architecture, Go function calls now use registers to pass arguments and results instead of the stack. This brings about a 5% performance improvement and a 2% reduction in binary size.
- Bounds Check Elimination: Improved bounds check elimination logic, further enhancing performance.
Standard Library
time: AddedTime.UnixMilliandTime.UnixMicromethods; addedTime.IsDSTmethod to check if it is currently Daylight Saving Time.testing: Added-shuffleflag to randomly shuffle test execution order; addedT.SetenvandB.Setenvmethods to set environment variables during tests.sync/atomic:atomic.ValueaddedSwapandCompareAndSwapmethods.net/http: Semicolons;are no longer allowed as separators in URL query parameters.runtime/cgo: AddedHandlemechanism for safely passing Go values between C and Go.
References
For more details, please refer to the official release notes: Go 1.17 Release Notes