What Is New in Go 1.9
| Category | Key Changes |
|---|---|
| Language | Type aliases, new math/bits package |
| Tools | Parallel compilation, test helper functions |
| Runtime | Concurrent map operations, monotonic time support |
| Libraries | New sync.Map, TLS 1.3 support, block profiling |
| Ports | New support for 64-bit MIPS, FreeBSD 10.3+ requirement |
What language changes were introduced in Go 1.9?
Go 1.9 added type aliases, a feature that lets you declare an alternative name for an existing type. This was primarily introduced to support large-scale codebase refactoring. The syntax is straightforward: type T1 = T2 makes T1 an alias for type T2.
In practice, this helps when breaking apart a large package into smaller ones without breaking existing users. You can create aliases for types that move to new locations, giving consumers time to migrate their code.
How did Go 1.9 improve the toolchain?
The compiler now processes functions in parallel within a package, which speeds up build times for multi-core machines. This parallel compilation happens automatically and doesn't require any changes to your build scripts.
Another tooling improvement is the addition of the t.Helper method in testing. When called from a helper function, it marks the function as a test helper, making test output clearer by skipping the helper's frame when reporting errors.
func testHelper(t *testing.T) {
t.Helper()
// helper logic here
}
What runtime enhancements came with Go 1.9?
The most significant runtime change was making most map operations safe for concurrent reads. While concurrent writes still require synchronization, multiple goroutines can now read from a map simultaneously without causing a race condition panic.
Go 1.9 also added support for monotonic time measurements through the time package. This ensures time comparisons and duration calculations aren't affected by system clock adjustments, which is crucial for measuring actual elapsed time.
What new libraries were added in this release?
The sync package gained sync.Map, a concurrent map designed for specific use cases where keys are stable and there are many concurrent readers. It's not a general replacement for a mutex-protected map but offers better performance in certain scenarios.
The math/bits package was introduced, providing optimized bit manipulation functions that compile to native machine instructions. These functions help when you need low-level control over integer representations.
TLS 1.3 support was added in an experimental capacity, giving developers early access to the newer, more secure protocol version. The crypto/tls package also saw performance improvements for both handshakes and data transmission.
FAQ
Should I use type aliases in new code?
Type aliases were mainly designed for incremental refactoring of large codebases. For new projects, it's usually better to use standard type declarations unless you have a specific need for aliasing.
Are concurrent map reads completely safe now?
Yes, concurrent reads are now safe without additional synchronization. However, any concurrent write operations still require proper synchronization using mutexes or other coordination mechanisms.
When should I use sync.Map instead of a regular map with a mutex?
Use sync.Map when you have a specific access pattern: many concurrent readers with few writers, and keys that don't change often. For most other cases, a standard map with proper locking is more appropriate.
Does parallel compilation affect build reproducibility?
No, the parallel compilation feature only affects build performance, not the final output. The resulting binaries are identical to those built with the serial compiler.
Is TLS 1.3 enabled by default in Go 1.9?
No, TLS 1.3 was available as an experimental feature in Go 1.9 but wasn't enabled by default. You had to explicitly enable it through configuration options in the crypto/tls package.