Find file
399e671 Feb 17, 2016
404 lines (218 sloc) 13.4 KB
Go 1.6 release party at Tokyo
GoCon Tokyo
17 Feb 2016
Taichi Nakashima
* About me
.image img/deeeet.png 200 _
- *@deeeet* / *@tcnksm* (GitHub)
- [[][]]
- A PaaS Dev&Ops (Using CloudFoundry)
- [[][gcli]] - The easy way to build Golang command-line application
- [[][gotests]] - A tool to generate Go test functions from the given source code like gofmt
- [[][ghr]] - Create Github Release and upload artifacts in parallel
- [[][license]] - Generate LICENSE file you want
- kafka-firehose-nozzle (Coming soon) - Integrate CloudFoundry with [[][Apache Kafka]]
- [[][go-input]] - Go package for ideal tty prompt
- [[][go-latest]] - Simple way to check version is latest or not from various sources in Go
* OSS (gotests)
.image img/gotests.gif 500 _
* Welcome
Today (Feb 17th) is an attempt at a release party for Go 1.6 involving as many Go user groups as possible.
* Welcome
* Welcome
There are NNN Go user groups taking part, you can find [[][a list of them here]].
This presentation is based _heavily_ on the [[][official Go 1.6 release notes]] and forked from [[][]] (by @davecheney).
* Go 1.6
The latest Go release, version 1.6, arrives six months after 1.5.
Most of its changes are in the implementation of the language, runtime, and libraries. There are no changes to the language specification.
As always, the release maintains the [[][Go 1 compatibility guarantee]].
Almost all Go programs are expected to continue to compile and run as before.
* The Go project by the numbers
Go was announced as an open source project November 10th, 2009.
Releases occur on a ~6 month cadence with several bug fix point releases between each major release.
Release timeline:
- [[][Go 1.0]] released 28th March, 2012
- [[][Go 1.1]] released 13th May, 2013
- Go 1.2 released 1st December, 2013
- Go 1.3 released 18th June, 2014
- Go 1.4 released 10th December, 2014
- [[][Go 1.5]] released 19th August, 2015
- Go 1.6 is expected to be released February, 2016
* New ports
Experimental ports to Linux on 64-bit MIPS (linux/mips64 and linux/mips64le).
Experimental port to Android on 32-bit x86 (android/386).
In the future:
- s390x (IBM Z series) planned for Go 1.7
- RISC-V may be on the horizon
* Agenda
- Standard library
- Runtime
- Tools
* Standard library
* Standard library
- HTTP/2
- text/template
- sort
- (Minor changes)
* HTTP/2
Go 1.6 adds transparent support in the `net/http` package for the new HTTP/2 protocol.
Bundled from [[][]]
bundle net/http http2
Go clients and servers will automatically use HTTP/2 as appropriate when using HTTPS.
Programs that must disable HTTP/2 can do so by setting `Transport.TLSNextProto` (for clients) or `Server.TLSNextProto` (for servers) to a non-nil, empty map.
* HTTP/2
_DEMO_ at [[][]]
.play src/h2.go
* HTTP/2
After Go1.6
- h2c (HTTP/2 over TCP) ?
- Server push ?
Read more
- [[][HTTP/2 demo site]] (powered by Go)
- [[][Here is a video of Brad Fitzpatrick giving an overview of Go 1.6's HTTP/2 support]] at the London Go Gathering in 2015.
- [[][Go言語とHTTP2 | SOTA]]
* Stripping whitespace with text/template
It is now possible to trim whitespaces around template actions, which can make template definitions more readable.
A minus sign at the beginning of an action says to trim space before the action, and a minus sign at the end of an action says to trim space after the action.
whitespace characters is the same as in Go: space, horizontal tab, carriage return, and newline.
* Stripping whitespace with text/template
.play src/template_trim.go
* {{block}} action
The new {{ block }} action is shorthand for defining a template ({{ define }}) and then executing it in place ({{ template }}).
{{ define "T1" }} T1 {{ end }}{{ template "T1" . }}
{{ block "T1" . }} T1 {{ end }}
* Template redefinition
.play src/template_redefine.go
Easy to reuse template. See more on [[][example]]
* sort.Sort is faster
In the sort package, the implementation of `Sort` has been rewritten to make about 10% fewer calls to the Interface's `Less` and `Swap` methods.
The new algorithm does choose a different ordering than before for values that compare equal (those pairs for which `Less(i,`j)` and `Less(j,`i)` are false).
The definition of `Sort` makes no guarantee about the final order of _equal_values_, the new behavior may break programs that expect a specific order.
Such programs should either refine their Less implementations to report the desired order or should switch to `sort.Stable`, which preserves the original input order of equal values.
* sort.Sort is faster (Bench)
.image img/bench-sort.png 400 _
.caption [[][]] by _Francesc_ _Campoy_
* Minor standard library changes
As well as the big improvements mentioned above, the standard library received many bug fixes and minor improvements.
This section highlights a few of these changes.
Read more
- [[][Go 1.6 release notes]]
* bufio
The bufio package's Scanner type now has a Buffer method, to specify an initial buffer and maximum buffer size to use during scanning.
func (s *Scanner) Buffer(buf []byte, max int)
This makes it possible, when needed, to scan tokens larger than MaxScanTokenSize.
* regexp
In the regexp package, the Regexp type has always been safe for use by concurrent goroutines.
Some high-concurrency servers using the same Regexp from many goroutines have seen degraded performance due to contention on a mutex protecting a cache of scratch spaces used during regular expression searches.
To help such servers, Regexp now has a Copy method, which makes a copy of a Regexp that shares most of the structure of the original but has its own scratch space cache.
re1 := regexp.MustCompile(`^(?P<root>github\.com/([A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+))(/[A-Za-z0-9_.\-]+)*$`)
re2 := re1.Copy()
A copy does have additional space overhead, so Copy should only be used when contention has been observed.
* time
The time package's Parse function has always rejected any day of month larger than 31, such as January 32.
In Go 1.6, Parse now also rejects February 29 in non-leap years, February 30, February 31, April 31, June 31, September 31, and November 31.
.play src/time.go
* Runtime
* Runtime
- maps panic if you misuse them
- Panic messages are shorter by default
- Garbege collector
* maps panic if you misuse them
The runtime has added lightweight, best-effort detection of concurrent misuse of maps.
If the runtime detects this condition, it prints a diagnosis and crashes the program.
fatal error: concurrent map writes
goroutine 2726 [running]:
runtime.throw(0x192d630, 0x15)
/usr/lib/go/src/runtime/panic.go:530 +0x90 fp=0xc8202eb838 sp=0xc8202eb820
The best way to find out more about the problem is to run the program under the race detector.
* Panic messages are shorter by default
For program-ending panics, the runtime now by default prints _only_the_stack_of_the_running_goroutine_, not all existing goroutines.
Usually only the current goroutine is relevant to a panic, so omitting the others significantly reduces irrelevant output in a crash message.
To see the stacks from all goroutines in crash messages, set the environment variable `GOTRACEBACK` to all or call `debug.SetTraceback` before the crash, and rerun the program.
env GOTRACEBACK=all ./crashy
Read more:
- [[][A whirlwind tour of Go’s runtime environment variables]]
* Garbage collector improvements
Go 1.5 introduced a low latency garbage collector.
The new collector trades throughput for reduced latency.
Allocations pay (in terms of time) a little up front to reduce the time taken to clean up later, this reduces the overall time the gc has to stop the world.
For Go 1.6, a lot of work went into optimising and tuning the gc, enabling far larger heaps to be managed within the 10ms latency goal.
* Go 1.5
At [[][GopherCon 2015 Rick Hudson gave a presentation]] about the Go 1.5 low latency collector
.image img/go15.png 400 _
* Go 1.6
At [[][QCon SF in November Rick Hudson]] gave an updated presentation which showed this comparison of Go 1.5 to the upcoming Go 1.6
.image img/go16.png 400 _
* Go1.5 (from twitter)
.image img/go15-com.png 500 _
.caption [[][]]
* Go1.6 (from twitter)
.image img/go16-com.png 500 _
.caption [[][]]
* Tools
* Tools
- Go vet
- Vendoring
- Compiler Toolchain
- -X flag
* Go vet command
The go vet command now diagnoses passing function or method values as arguments to Printf, such as when passing f where f() was intended.
.code src/vet.go
* Vendor support
Go 1.5 introduced experimental support for vendoring, enabled by setting the `GO15VENDOREXPERIMENT` environment variable to 1
Go 1.6 keeps the vendoring support, no longer considered experimental, and enables it by default.
It can be disabled explicitly by setting the GO15VENDOREXPERIMENT environment variable to 0. Go 1.7 will remove support for the environment variable.
The most likely problem caused by enabling vendoring by default happens in source trees containing an existing directory named vendor that does not expect to be interpreted according to new vendoring semantics. In this case, the simplest fix is to rename the directory to anything other than vendor and update any affected import paths.
* Vendored code matches ./...
If you're used to doing
% cd $GOPATH/
% go test ./...
Be aware that vendored packages, like
Will match the go tool glob operator `...`, and probably cause the test to fail.
The workaround is to filter out vendored packages by name
go test $(go list ./... | grep -v /vendor/)
Read More
- [[][Issue 11659]]
* Sharing pointers between Go and C
cgo continues to get stricter about sharing data between Go and C.
In short:
- Go can pass a pointer to C
- The referenced memory can't have pointers to Go allocated memory (Not allowed to pass Go pointer to Go pointer)
- C can't keep pointers to the memory after the call returns
These rules are checked by the runtime during program execution: if the runtime detects a violation, it prints a diagnosis and crashes the program.
The checks can be disabled by setting the environment variable `GODEBUG=cgocheck=0`, but note that disabling the checks will typically only lead to more mysterious failure modes.
* Sharing pointers between Go and C (cont.)
.play src/cgo.go
* Compiler Toolchain
Externally the compiler toolchain is mostly unchanged compared to Go 1.5.
Internally, the most significant change is that the parser is now hand-written instead of generated from yacc.
The new SSA compiler backend is slated to land, for amd64 only at this stage, in Go 1.7.
* Changes to the -X flag
In Go 1.5 the linker's -X flag changed.
In Go 1.4 and earlier, it took two arguments, as in
-X value
Go 1.5 added an alternative syntax using a single argument that is itself a name=value pair:
In Go 1.5 the old syntax was still accepted, after printing a warning suggesting use of the new syntax instead.
Go 1.6 continues to accept the old syntax and print the warning.
Go 1.7 will remove support for the old syntax.
* Performance
* Performance
On average the programs in the Go 1 benchmark suite run a few percent faster in Go 1.6 than they did in Go 1.5.
The garbage collector's pauses are even lower than in Go 1.5, although the effect is likely only noticeable for programs using a large amount of memory.
There have been significant optimizations bringing more than 10% improvements to implementations of the compress/bzip2, compress/gzip, crypto/aes, crypto/elliptic, crypto/ecdsa, and sort packages.
Read more
- [[][Go crypto: bridging the performance gap]]