One of the most common areas of bookkeeping encountered in system programs is managing the lifetimes of allocated objects. In languages such as C, it needs to be done manually, which can consume a lot of programmer time and often cause errors. Even in languages like C ++ or Rust, which provide help mechanisms, these mechanisms can have a significant impact on the design of the software, often adding their own programming overhead. We believe that eliminating such programmer overhead is critical, and advances in garbage collection technology over the past few years have given us confidence that garbage collection can be implemented easily enough and with low enough latency to be a viable approach for networked systems.
Much of the difficulty with concurrent programming stems from the object lifetime problem: when objects are passed between threads, it becomes cumbersome to ensure that they are safely released. Automatic garbage collection makes concurrent code much easier to write. Of course, implementing garbage collection in a concurrent environment is a challenge in itself.
Finally, concurrency aside, garbage collection makes interfaces simpler because they do not need to specify how memory is managed across interfaces.
This is not to say that recent work in languages such as Rust has led to new ideas about managing resources is wrong; We encourage this work and are happy to see it develop. But Go takes a more traditional approach to solving the object life problem through garbage collection, and garbage collection alone.
The current implementation of GO is a marker clearing collector. If the machine is multiprocessor, the collector runs in parallel with the main program on a separate CPU core. Major work on collectors in recent years has reduced pause times to the submillisecond range, even for heaps, all of which eliminates one of the major problems with garbage collection in web servers. We continue to work on improving our algorithms, further reducing overhead and wait times, and exploring new approaches. In his 2018 ISMM keynote, Rick Hudson of the Go team described the progress to date and suggested some ways forward.
On the topic of performance, keep in mind that Go gives programmers considerable control over memory layout and allocation, far more than is typical in garbage collection languages. The language can be used well by well-designed programmers, which can greatly reduce the overhead of garbage collection. For a working example, see the article on profiling the Go program, including a demonstration of Go’s profiling tools.
Golang golang.org/doc/faq#sta…