Go released recently version 1.12, with few changes on performance and most of the changes are done in the implementation of the tool chain, runtime, and libraries.
Table of contents we will see,
Here, I’m listing out the very major updates of Go 1.12.
- Runtime Performance
- Go command Line Tools
- Core packages
- Minor Changes On Go library
With latest changes, the race detector is now started to support on the linux/arm64.
This is the last release to support on FreeBSD 10.x, the coming releases are not going to support on FreeBSD 10.x. Go 1.13 will require FreeBSD 11.2+ or FreeBSD 12.0+. And, FreeBSD 12.0+ requires a kernel with the COMPAT_FREEBSD11 option set (this is the default).
cgo is now supported on linux/ppc64.
hurd is now a recognized value for GOOS, reserved for the GNU/Hurd system for use with gccgo.
When heap memory comes to its brim, Go 1.12 automatically improves the performance of garbage collection, which in turn to reduce the allocation latency.
The Go runtime now releases memory more aggressively to the operating system than its previous version, particularly in response to large allocations that can’t reuse existing heap space.
The Go 1.1.2 got improved performance by providing faster runtime’s and deadline code which in turns to give better performance even when there’s more number of CPUs are used. Also helps to improve the performance while manipulating network connection deadlines.
Go 1.12 improves the accuracy of memory profiles by fixing and over counting the large heap allocations.
Improved Go Command Line Tools
Now that we have the cmd/go ‘go doc‘ CLI for getting documentation. Godoc is not going to support from the future releases and we should have to use go doc instead of godoc.
For the CLI support and to avoid confusions, they yet to remove the godoc and it is going to be available only on web server.
Go 1.12 is the last release that will include the godoc webserver; in Go 1.13 it will be available via go get.
go doc now supports -all flag, which will help us to print all exported APIs and their documentation, as like how the godoc command line used to do. And, also now includes the -src flag, which will show the target’s source code.
cmd/go tool vet:
The ‘go tool vet’ command has been rewritten like go vet which will serve as the base for different source code analysis tools.
As part of this, external tools that use go tool vet must be changed to use go vet which will be supported by all versions of Go. So the experimental -shadow option is no longer available with go vet.
Currently, you can check the variable shadowing using,
You will no longer use go tour in the main binary distribution henceforth and if you want to get the support or run the tour in your local machine then you can install it manually by using this,
go get -u golang.org/x/tour
Core Updates On Golang Packages
Go 1.12 adds opt-in support for TLS 1.3 in the crypto/tls package as specified by RFC 8446. It can be enabled by adding the value tls13=1 to the GODEBUG environment variable. From the coming releases, It will be enabled defaultly.
To negotiate TLS 1.3, make sure you do not set an explicit MaxVersion in Config and run your program with the environment variable GODEBUG=tls13=1 set.
All TLS 1.2 features except TLSUnique in ConnectionState and renegotiation are available in TLS 1.3 and provide equivalent or better security and performance.
Minor Changes To The Go Library
In this release, there are various minor changes and updates are done on library. Here, I’m describing few of packages.
fmt: Print maps in sorted order which is easier debugging. Also remember that fmt output is now deterministic.
Testing: Run test N times, instead of testing for N seconds. For example, -benchtime=100x will run the benchmark for 100 times. Now, it will also compare before/after number of executions better.
Strings: Builder.Cap method is introduced which returns capacity of builder’s byte slice otherwise it will be impossible to tell or free up the space.
OS: Introduced ProcessState.ExitCode method which is easy to get a process’s exit code so you no need to type assert to a syscall type.
Crypto/Rand: If the read is blocked more than 60 seconds, it will give a warning as a standard error that help us to solve the issue easier. Otherwise the programs might hang with no apparent reason.
Math/Bits: Added extended precision Add, Sub, Mul, Div for doing easy arithmetic multi-words (uint128, etc) and it will be faster than the manual coding.
Text/Template: Panics in user code are now returned as errors.
- Templates are simpler to use
- Friendlier to handle errors