Today, August 16, 2016, the eighth stable release of the Go - Go 1.7 programming language has been released. As usual, the release was released according to the plan, half a year after the previous one, and there are no inversely incompatible changes in it. At the same time, Go 1.7 has a lot of new and important changes, compilation times and sizes of binaries have been reduced, the speed has been increased, and the context package has finally been added to the standard library. Under the cat a more detailed overview of the innovations and innovations.
Perhaps one of the most important changes in this release is the use of a new backend compiler that supports SSA- form (Static Single-Assigment). Switching to SSA-backend gives new opportunities for optimizing and generating more efficient code, and this can already be seen in this release.
To compare the result of compiling old and new backends, just pass the parameter to the go build command:
go build -gcflags="-ssa=0"
and for new (SSA is enabled by default in Go 1.7).
go build
Switching to a new backend now gives an increase in the speed of programs from 5 to 35%.
You can also delve into the code generated by the backend using the GOSSAFUNC variable:
GOSSAFUNC=main go build && open ssa.html
Although this change is completely invisible to ordinary users, it is worth mentioning. Go 1.7 uses the new metadata export format in binary files, which is more compact and efficient than the previous one. It fixes some stale bugs and generates smaller binaries. It can be disabled with the -newexport = 0 option
go build -newexport=0
Although we usually expect that binaries compiled with downloadable Go versions will work in all future versions of different OSs - in the case of the not yet released MacOS X 10.12, this is not the case. In this release of MacOS, the implementation of the gettimeofday () system call was changed, and in Go, a copy of its implementation is actually used, so when it changed in the kernel, I had to change the code in Go. How can this be reflected in practice? Mac OS X binaries compiled with Go <1.6.3 will not work correctly on MacOS X 10.12 'Sierra'. If you distribute in binaries, be sure to build them with Go 1.6.3 or 1.7 so that they work correctly on MacOS X 10.12.
In addition to the above points, many components of the standard library, compiler, and linker have been optimized, with the result that binaries should be 20-30% smaller in size, and the code should work much faster (especially on x86-64 platforms) than Go 1.6. At the same time, thanks to the new backend, there is still a lot of space for the planned optimizations for the next releases.
Also in some packages of the standard optimization library added more than 10% acceleration - crypto / sha1, crypto / sha256, encoding / binary, fmt, hash / adler32, hash / crc32, hash / crc64, image / color, math / big, strconv, strings, unicode and unicode / utf16.
Also in programs with a large number of garutin-launched garbage collector pauses should be much less.
One of the most anticipated additions to the standard library was the transfer of the golang.org/x/net/context package into context . The word "net" was removed from the name because, although the context is most often used in code that deals with requests from the network, its functionality is not limited to working with the network. For example, it can be used for os / exec and other things.
Why is it important? In Go, a lot of http frameworks and packages appeared, the task of which was to provide context transfer inside incoming request handlers. net / context gradually began to occupy this niche, but now, with context in the standard library and with its native support in the net, net / http and os / exec packages, writing code that works with query contexts will be much easier and more unified.
The net package has a new method of type Dialer :
func (d *Dialer) DialContext(ctx context.Context, network, address string) (Conn, error)
If the context timeout expires before the connection is established, DialContext returns an error.
In net / http , the Context () and WithContext () methods appeared in the Request type:
func (r *Request) Context() context.Context
func (r *Request) WithContext(ctx context.Context) *Request
The Context () method is used to get the request context, to change it, use WithContext (). In outgoing requests, the context now controls the cancellation of the request.
In this release, the GO15VENDOREXPERIMENT variable is no longer supported, now the vendoring is the standard Go functionality.
The testing package, which is used to write tests, has added support for nested hierarchical tests and benchmarks. This is very convenient for BDD testing, tabular tests and for a more compact organization of tests in general. Code example:
func TestTeardownParallel(t *testing.T) { // This Run will not return until the parallel tests finish. t.Run("group", func(t *testing.T) { t.Run("Test1", parallelTest1) t.Run("Test2", parallelTest2) t.Run("Test3", parallelTest3) }) // <tear-down code> }
Details are available in the package documentation: https://golang.org/pkg/testing/#hdr-Subtests_and_Sub_benchmarks
Full list of changes is available here: https://golang.org/doc/go1.7
Usually there are no risks with updating to a new release, and in Go community the latest version is used by the majority. But it makes sense to wait the first couple of weeks, test builds for 1.7 in test mode. In the last two releases there were minor releases (1.5.1 and 1.6.1) with fixes for very specific bugs found in the first weeks after the main release.
https://golang.org/doc/go1.7
https://golang.org/dl/
Ps. This release was attended by 170 people, of whom 140 are not from Google, but from the Go community.
Source: https://habr.com/ru/post/307864/
All Articles