Google Go 1.5 Revs Garbage Collection, More
That conversion from C to Go was the largest change for the Go team, but it enabled what is probably the most important change in Go 1.5, which is the introduction of the concurrent garbage collector. The simplest garbage collector you can imagine is called stop-the-world and it completely stops program execution, which is the "world," so nothing in memory is moving anymore and it looks for what in memory is not needed anymore and it frees that garbage for reallocation and then it lets the world start again. The period of time that the "world" is stopped is called a GC pause. The problem here is that the more memory you have, the more time it takes to look thru it and the longer the GC pause is. A GC pause of a second or two is a long pause, and the standard solution is to make the garbage collector concurrent, which means it can do what it does while the rest of the program is running. Over a year ago, Google hired a garbage collection expert named Rick Hudson who had invented a number of significant garbage collection techniques. He started working on a concurrent collector designed for Go specifically and that collector is what the company released in Go 1.5. That new collector solves the latency problem—where at the worst case, Google was seeing one to two second pauses on really complex programs, now they are seeing 10 to 20 millisecond pauses on those same programs. And more normal-sized programs see pauses in the one millisecond range, Cox said. "So that's a 100x improvement, which is not something we see every day," he said. "Related improvements to the scheduler allowed us to change the default GOMAXPROCS value (the number of concurrently executing goroutines) from 1 to the number of available CPUs," said Andrew Gerrand, a Google engineer working on Go, in a blog post on Go 1.5. "Changes to the linker enable distributing Go packages as shared libraries to link into Go programs, and building Go packages into archives or shared libraries that may be linked into or loaded by C programs (design doc).""There are also several new operating system and architecture ports," Gerrand said. "The more mature new ports are darwin/arm, darwin/arm64 (Apple's iPhone and iPad devices), and linux/arm64. There is also experimental support for ppc64 and ppc64le (IBM 64-bit PowerPC, big and little endian). The new darwin/arm64 port and external linking features fuel the Go mobile project, an experiment to see how Go might be used for building apps on Android and iOS devices. (The Go mobile work itself is not part of this release.)" Thus, the fourth new feature is important for some server environments, and also for support for the iPhone and the iPad, Cox said. The goal of the mobile experiment is to explore the use of Go as a Native Development Kit (NDK) language on mobile devices like Android and iOS. Today, the primary NDK language on those devices is C++. "We designed and built Go initially as an alternative to C++ for backends on servers, but modern mobile apps tend to be structured the same way, so we think Go could be useful there, too," Cox said.
Meanwhile, the third big new feature, being able to call Go libraries from C or C++ programs, is important when you have existing C or C++ programs and you want to add a piece written in Go or rewrite a piece written in Go. Before Go 1.5, it was possible for Go to call C libraries, but it wasn't possible for C to call Go libraries. Now it is. This same work made it possible to compile a Go program as a collection of shared libraries, which is important to some Linux distributions, Cox said.