days
1
7
hours
0
3
minutes
1
7
seconds
3
6
search

Go 1.9 is here

Gabriela Motroc
Go 1.9

© Shutterstock / fotogestoeber

The wait is over! Go 1.9 is finally here and it comes bearing gifts (a.k.a. changes). Read on to find out what’s new.

If Go 1.9 sounds familiar, that’s because we covered the topic a couple of months ago, when the Go team published the draft release notes. The 10th release in the Go 1.x series brings two changes to the language: adding support for type aliases and defining when implementations may fuse floating point operations.

According to the release notes, most of the changes are in the implementation of the toolchain, runtime, and libraries. 1.9 adds transparent monotonic time supportparallelizes compilation of functions within a package, better supports test helper functions, includes a new bit manipulation package, and has a new concurrent map type.

Go 1.9 language highlight — Introduction of type aliases

The introduction of type aliases is the most important change to the language, according to the blog post announcing the new release.

The proposal by Russ Cox and Robert Griesemer to add type aliases support is a replacement for the generalized alias proposal originally targeted for, but held back from, the previous release. They wrote in the proposal that “the primary motivation is to enable gradual code repair during large-scale refactorings, in particular moving a type from one package to another in such a way that code referring to the old name interoperates with code referring to the new name. Type aliases may also be useful for allowing large packages to be split into multiple implementation packages with a single top-level exported API, and for experimenting with extended versions of existing packages.”

In short, a type alias declaration has the form:

type T1 = T2

This declaration introduces an alias name T1—an alternate spelling—for the type denoted by T2; that is, both T1and T2 denote the same type.

As exciting as this might be, the introduction of type aliases is not the only change. The language specification now states when implementations are allowed to fuse floating point operations together, such as by using an architecture’s “fused multiply and add” (FMA) instruction to compute x*y + z without rounding the intermediate result x*y. To force the intermediate rounding, write float64(x*y) + z.

SEE ALSO: The meteoric rise of Go and why HashiCorp is betting on it

Performance

Most programs should run a bit faster, due to speedups in the garbage collector, better-generated code, and optimizations in the core library.

Garbage Collector

Library functions that used to trigger stop-the-world garbage collection now trigger concurrent garbage collection. Specifically, runtime.GCdebug.SetGCPercent, and debug.FreeOSMemory, now trigger concurrent garbage collection, blocking only the calling goroutine until the garbage collection is done.

The debug.SetGCPercent function only triggers a garbage collection if one is immediately necessary because of the new GOGC value. This makes it possible to adjust GOGC on-the-fly.

Large object allocation performance is significantly improved in applications using large (>50GB) heaps containing many large objects.

The runtime.ReadMemStats function now takes less than 100µs even for very large heaps.

For a full list of the changes, check out the release notes

Author
Gabriela Motroc
Gabriela Motroc is editor of JAXenter.com and JAX Magazine. Before working at Software & Support Media Group, she studied International Communication Management at the Hague University of Applied Sciences.

Leave a Reply

Be the First to Comment!

avatar
400
  Subscribe  
Notify of