What Is New in Go 1.6
Go 1.6 introduces several key enhancements focused on the runtime, standard library, and tooling. The most significant changes improve garbage collection performance and HTTP/2 support.
| Category | Key Changes |
|---|---|
| Runtime | Low-latency garbage collector, concurrent stack shrinking |
| Standard Library | Automatic HTTP/2 support, vendor directory support, new context package |
| Tools | Go command changes, cgo pointer sharing rules |
| Minor Changes | Template parsing, crypto, and os package updates |
How did garbage collection performance improve?
The runtime now features a garbage collector that pauses programs for dramatically less time. It achieves this by running parts of the collection work concurrently with the application.
In practice, this means your Go servers can handle more requests with lower and more consistent latency. The collector also introduces concurrent stack shrinking, which further reduces stop-the-world pauses during goroutine stack reclamation.
What changed with HTTP/2 support?
HTTP/2 support is now automatic for both servers and clients using the net/http package. The package will use HTTP/2 by default when TLS (https://) is configured.
This matters because you no longer need to explicitly enable it. For servers, just using ListenAndServeTLS is enough. For clients, requests to HTTPS URLs will automatically use HTTP/2 if the server supports it.
How does the vendor directory work?
Go 1.6 introduces experimental support for a vendor directory. The go tool now recognizes a directory named vendor next to your main module and uses it to satisfy dependencies.
This provides a simple mechanism for vendoring dependencies without external tools. The tool searches the vendor directory before the GOPATH, giving you more control over your project's dependencies.
What is the new context package?
The context package has been moved from golang.org/x/net/context into the standard library. It provides a standard way to carry request-scoped values, cancellation signals, and deadlines across API boundaries.
This formalizes a pattern that was already widely used in Go servers and clients. It's essential for building scalable services that need to manage request lifetimes and propagate cancellation.
Were there any changes to cgo?
Yes, the rules for sharing pointers between Go and C code have been relaxed. The cgo mechanism is now more permissive about what Go pointers can be passed to C functions.
This change makes it easier to work with certain C libraries that expect more complex pointer structures. However, the rules are still strict to ensure memory safety, so you should review the updated documentation.
FAQ
Do I need to change my code to benefit from the new garbage collector?
No, the improvements are automatic. Your existing Go programs should immediately experience shorter GC pauses without any code modifications.
Will my HTTP server automatically use HTTP/2?
Yes, if you're using TLS with ListenAndServeTLS, your server will automatically support HTTP/2 for compatible clients. No code changes are required.
Is the vendor directory feature stable?
It's marked as experimental in Go 1.6. The feature works but the semantics might be refined in future releases based on community feedback.
What happened to the old x/net/context package?
It's now available as context in the standard library. You should update your imports from golang.org/x/net/context to just context.
Are the new cgo pointer rules backward compatible?
Most existing code will continue to work, but some previously illegal code that happened to work might now be caught. The runtime includes better checking for pointer misuse.