Go 1.14 and Beyond

What we know already

Andreas Linz—klingt.net

2019-11-14T19+01:00

Go 1.14

Embedding of overlapping interfaces

$ docker run -v $PWD:/app -w /app --rm -it golang:1.13 go run overlapping-interfaces.go
./overlapping-interfaces.go:10:2: duplicate method Close
$ docker run -v $PWD:/app -w /app --rm -it golang:1.14-rc go run overlapping-interfaces.go
works

GOINSECURE

  • instuct go command to skip certificate validation or accept HTTP
  • useful when developing a module proxy
  • GOINSECURE=localhost go get foo/bar

Vendoring

  • if go.mod specifies Go 1.14 and a /vendor folder present then commands will default to using vendoring
  • usage of modules can be enforced with -mod=mod

Test log output

  • output of go test -v (or t.Log) is now streamed instead of being presented at the end of all tests

Runtime Improvements

(almost) Zero Overhead defer

This release improves the performance of most uses of defer to incur almost zero overhead compared to calling the deferred function directly. As a result, defer can now be used in performance-critical code without overhead concerns.

More Efficient Page Allocator

The page allocator is more efficient and incurs significantly less lock contention at high values of GOMAXPROCS. This is most noticeable as lower latency and higher throughput for large allocations being done in parallel and at a high rate.

Discord should consider to reevaluate their switch from Go to Rust 😉.

New package hash/maphash

  • collision-resistant
  • not cryptographically secure
  • hash functions map arbitrary string/[]byte to 64-bit integers
  • useful for building custom maps
  • not safe for concurrent use by multiple goroutines (can be initialized with the same seed to get equal hashes)

Minor Library Changes

crypto/tls

  • SSL3 support removed
  • TLS1.3 can not be disabled using GODEBUG anymore
  • when multiple certificate chains are configured) the first compatible with the peer is selected automatically (e.g. for providing ECDSA and RSA certificates)

ioutil.TempDir

  • ioutil.TempDir allows to specify a naming pattern (like TempFile)
  • useful when cleaning up temporary stuff of an application (e.g. rm -rf /tmp/my-app-*)
$ docker run -v $PWD:/app -w /app --rm -it golang:1.14-rc go run predictable-tempdir.go
/tmp/584949244-my-app
/tmp/my-app-532238635

Go 1.15

  • proposals
  • scheduled for August 2020
  • no major changes

Int to String

  • cmd/vet warn about int to string conversion
  • just replace those ints with runes
  • example: string(10) is "\n" not "10"
  • unicode/utf8 provides runeToString (play)

Impossible interface-interface assertion

Currently, Go permits any type assertion x.(T) (and corresponding type switch case) where the type of x and T are interfaces.

  • example: Two methods with the same name buth different signature (play)
  • impossible conversion is known at compile-time
  • cmd/vet will warn about this (will be a compile error later)

Constant-evaluate index and slice expressions

Future

The primary goals for Go remain package and version management, better error handling support, and generics.

f, err := os.Open(filename)
if err != nil {
    return …, err  // zero values for other results, if any
}
// with try
f := try(os.Open(filename))

we are also making progress on the generics front (more on that later this year).