## DRAFT RELEASE NOTES - Introduction to Go 1.9

Go 1.9 is not yet released. These are work-in-progress release notes. Go 1.9 is expected to be released in August 2017.

The latest Go release, version 1.9, arrives six months after Go 1.8 and is the tenth release in the Go 1.x series. There is one change to the language, adding support for type aliases. Most of the changes are in the implementation of the toolchain, runtime, and libraries. As always, the release maintains the Go 1 promise of compatibility. We expect almost all Go programs to continue to compile and run as before.

The release adds transparent monotonic time support, parallelizes compilation of functions within a package, better supports test helper functions, includes a new bit manipulation package, and has a new concurrent map type.

## Changes to the language

There is one change to the language. Go now supports type aliases to support gradual code repair while moving a type between packages. The type alias design document and an article on refactoring cover the problem in detail. In short, a type alias declaration has the form:

    type T1 = T2

This declaration introduces an alias name `T1`—an alternate spelling—for the type denoted by `T2`; that is, both `T1` and `T2` denote the same type.

## Ports

There are no new supported operating systems or processor architectures in this release.

### ppc64x requires Power8

Both `GOARCH=ppc64` and `GOARCH=ppc64le` now require at least Power8 support. In previous releases, only `GOARCH=ppc64le` required Power8 and the big endian `ppc64` architecture supported older hardware.

### Known Issues

There are some instabilities on FreeBSD that are known but not understood. These can lead to program crashes in rare cases. See issue 15658. Any help in solving this FreeBSD-specific issue would be appreciated.

## Tools

### Parallel Compilation

The Go compiler now supports compiling a package's functions in parallel, taking advantage of multiple cores. This is in addition to the `go` command's existing support for parallel compilation of separate packages. Parallel compilation is on by default, but can be disabled by setting the environment variable `GO19CONCURRENTCOMPILATION` to `0`.

### Compiler Toolchain

Complex division is now C99-compatible. This has always been the case in gccgo and is now fixed in the gc toolchain.

The linker will now generate DWARF information for cgo executables on Windows.

The compiler now includes lexical scopes in the generated DWARF, allowing debuggers to hide variables that are not in scope. The `.debug_info` section is now DWARF version 4.

### Go test

The `go` `test` command accepts a new `-list` flag, which takes a regular expression as an argument and prints to stdout the name of any tests, benchmarks, or examples that match it, without running them.

## Performance

As always, the changes are so general and varied that precise statements about performance are difficult to make. Most programs should run a bit faster, due to speedups in the garbage collector, better generated code, and optimizations in the core library.

TODO: There have been significant optimizations bringing more than 10% improvements to implementations in the `encoding/gob`, and ... packages.

### Garbage Collector

Library functions that used to trigger stop-the-world garbage collection now trigger concurrent garbage collection. Specifically, `runtime.GC`, `debug.SetGCPercent`, and `debug.FreeOSMemory`, now trigger concurrent garbage collection, blocking only the calling goroutine until the garbage collection is done.

The `debug.SetGCPercent` function only triggers a garbage collection if one is immediately necessary because of the new GOGC value. This makes it possible to adjust GOGC on-the-fly.

Large object allocation performance is significantly improved in applications using large (>50GB) heaps containing many large objects.

The `runtime.ReadMemStats` function now takes less than 100µs even for very large heaps.

## Core library

### Transparent Monotonic Time support

The `time` package now transparently tracks monotonic time in each `Time` value, making computing durations between two `Time` values a safe operation in the presence of wall clock adjustments. See the package docs and design document for details.

### New bit manipulation package

Go 1.9 includes a new package, `math/bits`, with optimized implementations for manipulating bits. On most architectures functions in this package are additionally recognized by the compiler and treated as intrinsics for additional performance.

### Test Helper Functions

The new `(*T).Helper` an `(*B).Helper` methods mark the calling function as a test helper function. When printing file and line information, that function will be skipped. This permits writing test helper functions while still having useful line numbers for users.

### Concurrent Map

The new `Map` type in the `sync` package is a concurrent map with amortized-constant-time loads, stores, and deletes. It is safe for multiple goroutines to call a Map's methods concurrently.

### Minor changes to the library

As always, there are various minor changes and updates to the library, made with the Go 1 promise of compatibility in mind.

archive/zip

  The ZIP `Writer` now sets the UTF-8 bit in the `FileHeader.Flags` when appropriate.

crypto/rand

  On Linux, Go now calls the `getrandom` system call without the `GRND_NONBLOCK` flag; it will now block until the kernel has sufficient randomness. On kernels predating the `getrandom` system call, Go continues to read from `/dev/urandom`.

crypto/x509

  On Unix systems the environment variables `SSL_CERT_FILE` and `SSL_CERT_DIR` can now be used to override the system default locations for the SSL certificate file and SSL certificate files directory, respectively.

  The FreeBSD path `/usr/local/etc/ssl/cert.pem` is now included in the certificate search path.

  The package now supports excluded domains in name constraints. In addition to enforcing such constraints, `CreateCertificate` will create certificates with excluded name constraints if the provided template certificate has the new field `ExcludedDNSDomains` populated.

database/sql

  The package will now use a cached `Stmt` if available in `Tx.Stmt`. This prevents statements from being re-prepared each time `Tx.Stmt` is called.

  The package now allows drivers to implement their own argument checkers by implementing `driver.NamedValueChecker`. This also allows drivers to support `OUTPUT` and `INOUT` parameter types. `Out` should be used to return output parameters when supported by the driver.

  `Rows.Scan` can now scan user-defined string types. Previously the package supported scanning into numeric types like `type Int int64`. It now also supports scanning into string types like `type String string`.

  The new `DB.Conn` method returns the new `Conn` type representing an exclusive connection to the database from the connection pool. All queries run on a `Conn` will use the same underlying connection until `Conn.Close` is called to return the connection to the connection pool.

encoding/asn1

  The new `NullBytes` and `NullRawValue` represent the `ASN.1 NULL` type.

encoding/base32

  The new Encoding.WithPadding method adds support for custom padding characters and disabling padding.

fmt

  The sharp flag ('`#`') is now supported when printing floating point and complex numbers. It will always print a decimal point for `%e`, `%E`, `%f`, `%F`, `%g` and `%G`; it will not remove trailing zeros for `%g` and `%G`.

hash/fnv

  The package now includes 128-bit FNV-1 and FNV-1a hash support with `New128` and `New128a`, respectively.

html/template

  The package now reports an error if a predefined escaper (one of "html", "urlquery" and "js") is found in a pipeline and its rewriting by the contextual auto-escaper could potentially lead to security or correctness issues.

image

  The `Rectangle.Intersect` method now returns a zero `Rectangle` when called on adjacent but non-overlapping rectangles, as documented. In earlier releases it would incorrectly return an empty but non-zero `Rectangle`.

image/color

  The YCbCr to RGBA conversion formula has been tweaked to ensure that rounding adjustments span the complete [0, 0xffff] RGBA range.

image/png

  The new `Encoder.BufferPool` field allows specifying an `EncoderBufferPool`, that will be used by the encoder to get temporary `EncoderBuffer` buffers when encoding a PNG image. The use of a `BufferPool` reduces the number of memory allocations performed while encoding multiple images.

  The package now supports the decoding of transparent 8-bit grayscale ("Gray8") images.

math/big

  The new `IsInt64` and `IsUint64` methods report whether an `Int` may be represented as an `int64` or `uint64` value.

mime/multipart

  The new `FileHeader.Size` field describes the size of a file in a multipart message.

net

  TODO: https://golang.org/cl/32572: add Resolver.StrictErrors

  TODO: https://golang.org/cl/37260: allow Resolver to use a custom dialer

  TODO: https://golang.org/cl/37402: implement deadline functionality on Pipe

  TODO: https://golang.org/cl/40510: don't enclose non-literal IPv6 addresses in square brackets

  TODO: https://golang.org/cl/40512: validate network in Dial{,IP} and Listen{Packet,IP} for IP networks

  The new methods `TCPConn.SyscallConn`, `IPConn.SyscallConn`, `UDPConn.SyscallConn`, and `UnixConn.SyscallConn` provide access to the connections' underlying file descriptors.

net/http

  Server changes:

  - `ServeMux` now ignores ports in the host header when matching handlers. The host is matched unmodified for `CONNECT` requests.
  - `Server.WriteTimeout` now applies to HTTP/2 connections and is enforced per-stream.
  - HTTP/2 now uses the priority write scheduler by default. Frames are scheduled by following HTTP/2 priorities as described in RFC 7540 Section 5.3.

  Client & Transport changes:

  - The `Transport` now supports making requests via SOCKS5 proxy when the URL returned by `Transport.Proxy` has the scheme `socks5`.

net/http/fcgi

  The new `ProcessEnv` function returns FastCGI environment variables associated with an HTTP request for which there are no appropriate `http.Request` fields, such as `REMOTE_USER`.

net/http/httptest

  The new `Server.Client` method returns an HTTP client configured for making requests to the test server.

  The new `Server.Certificate` method returns the test server's TLS certificate, if any.

net/rpc

  TODO: https://golang.org/cl/38474: Create empty maps and slices as return type

os

  TODO: https://golang.org/cl/37915: parse command line without shell32.dll

  TODO: https://golang.org/cl/41830: do not report ModeDir for symlinks on windows

os/exec

  The `os/exec` package now prevents child processes from being created with any duplicate environment variables. If `Cmd.Env` contains duplicate environment keys, only the last value in the slice for each duplicate key is used.

os/user

  `Lookup` and `LookupId` now work on Unix systems when `CGO_ENABLED=0` by reading the `/etc/passwd` file.

  `LookupGroup` and `LookupGroupId` now work on Unix systems when `CGO_ENABLED=0` by reading the `/etc/group` file.

reflect

  The new `MakeMapWithSize` function creates a map with a capacity hint.

runtime

  Tracebacks generated by the runtime and recorded in profiles are now accurate in the presence of inlining. To retrieve tracebacks programmatically, applications should use `runtime.CallersFrames` rather than directly iterating over the results of `runtime.Callers`.

  On Windows, Go no longer forces the system timer to run at high resolution when the program is idle. This should reduce the impact of Go programs on battery life.

  On FreeBSD, `GOMAXPROCS` and `runtime.NumCPU` are now based on the process' CPU mask, rather than the total number of CPUs.

  The runtime has preliminary support for Android O.

runtime/pprof

  TODO: https://golang.org/cl/34198: add definitions of profile label types

runtime/trace

  The execution trace now displays mark assist events, which indicate when an application goroutine is forced to assist garbage collection because it is allocating too quickly.

  "Sweep" events now encompass the entire process of finding free space for an allocation, rather than recording each individual span that is swept. This reduces allocation latency when tracing allocation-heavy programs. The sweep event shows how many bytes were swept and how many were reclaimed.

sync

  `Mutex` is now more fair.

syscall

  The new field `Credential.NoSetGroups` controls whether Unix systems make a `setgroups` system call to set supplementary groups when starting a new process.

  On 64-bit x86 Linux, process creation latency has been optimized with use of `CLONE_VFORK` and `CLONE_VM`.

  The new `Conn` interface describes some types in the `net` package that can provide access to their underlying file descriptor using the new `RawConn` interface.

testing/quick

  The package now chooses values in the full range when generating `int64` and `uint64` random numbers; in earlier releases generated values were always limited to the [-262, 262) range.

text/template

  The handling of empty blocks, which was broken by a Go 1.8 change that made the result dependent on the order of templates, has been fixed, restoring the old Go 1.7 behavior.

time

  The new methods `Duration.Round` and `Duration.Truncate` handle rounding durations away from and towards zero, respectively.

  Retrieving the time and sleeping now work correctly under Wine.