After trying Go for the first time recently, I am amazed with how fast the programs compile. The compiled code ends up being in machine code, and no intermediate virtual machine is required. However, there is one piece that is present in each executable i.e. the garbage collector - GC.
But, how does GC work in Go? How tunable is it? For now this is what I have found:
On the topic of performance, keep in mind that Go gives the programmer considerable control over memory layout and allocation, much more than is typical in garbage-collected languages. A careful programmer can reduce the garbage collection overhead dramatically by using the language well; see the article about profiling Go programs for a worked example, including a demonstration of Go’s profiling tools.
Go 1.5 concurrent garbage collector pacing
- The garbage collector has been re-engineered for 1.5 as part of the development outlined in the design document. Expected latencies are much lower than with the collector in prior releases, through a combination of advanced algorithms, better scheduling of the collector, and running more of the collection in parallel with the user program. The “stop the world” phase of the collector will almost always be under 10 milliseconds and usually much less.
- https://golang.org/s/go15gcpacing
- https://golang.org/doc/go1.5#gc
Go 1.4 release
- makes some internal changes to enable better GC in next releases ( Go 1.5 )
- https://golang.org/doc/go1.4#introduction
- Go 1.4+ Garbage Collection (GC) Plan and Roadmap - https://golang.org/s/go14gc
Go 1.3 release
- For a while now, the garbage collector has been precise when examining values in the heap; the Go 1.3 release adds equivalent precision to values on the stack. This means that a non-pointer Go value such as an integer will never be mistaken for a pointer and prevent unused memory from being reclaimed.
- https://golang.org/doc/go1.3#garbage_collector
Go 1.2 release
- The garbage collector has been made more parallel, which can reduce latencies for programs running on multiple CPUs.
- The garbage collector is also more precise, which costs a small amount of CPU time but can reduce the size of the heap significantly, especially on 32-bit architectures.
- https://golang.org/doc/go1.1#performance
Go 1.0 release
- Stop The World garbage collector ?
For an in-depth survey of Garbage Collection algorithms, there as an excellent book. The Garbage Collection Handbook - http://gchandbook.org/
I am simply amazed by the speed at which Go programs compile. Following the above pattern, it feels that Go is the way to Go for many software development tasks.
If that isn’t enough checkout whats upcoming in Go 1.6 - http://www.infoq.com/news/2015/09/go-16-garbage-collection