├── README.md ├── examples ├── alias.go ├── math-bits.go ├── testing-helper.go └── time-string.go ├── img └── party-gopher.png └── presentation.slide /README.md: -------------------------------------------------------------------------------- 1 | # Go 1.9 Release Party 2 | 3 | [View this presentation online](https://talks.godoc.org/github.com/davecheney/go-1.9-release-party/presentation.slide) 4 | 5 | This repository is a companion to the [Go 1.9 release party](https://github.com/golang/cowg/blob/master/events/2017-08-go1.9-release-party.md) on August 25, 2017. 6 | 7 | ## How can you help? 8 | 9 | If you would like to help improve this deck, you're strongly encouraged to do so. 10 | 11 | In particular we're looking for: 12 | 13 | - Detailed explanations, _with code!_, of new features or changes. If you have a code example or sample code, consider placing them in another repository and linking to it from this presentation. 14 | - Performance reports and graphs from _production_ environments showing the impact of Go 1.9. 15 | - Links, links, URLs, citations, and links. 16 | 17 | If you don't know where to start, [please consult the list of open issues](https://github.com/davecheney/go-1.9-release-party/issues) or grep the presentation for `TODO`. 18 | 19 | ## License and Materials 20 | 21 | This presentation is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/) licence. 22 | -------------------------------------------------------------------------------- /examples/alias.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type A struct { a int } 4 | 5 | type B struct { a int } 6 | 7 | type C B 8 | 9 | type D = B 10 | 11 | func main() { 12 | var ( a A; b B; c C; d D ) 13 | a = b // nope 14 | b = c // also nope 15 | d = b // new in Go 1.9! 16 | } 17 | -------------------------------------------------------------------------------- /examples/math-bits.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math/bits" 6 | ) 7 | 8 | //START OMIT 9 | func main() { 10 | a := uint8(0x88) 11 | b := bits.RotateLeft8(a, 2) 12 | fmt.Printf("a: %8.b\nb: %8.b", a, b) 13 | } 14 | 15 | //END OMIT 16 | -------------------------------------------------------------------------------- /examples/testing-helper.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "errors" 5 | "regexp" 6 | "testing" 7 | ) 8 | 9 | //START,OMIT 10 | func Something() error { return errors.New("oops") } 11 | 12 | func TestSomething(t *testing.T) { 13 | err := Something() 14 | checkErr(t, err) // line 16 15 | } 16 | 17 | func checkErr(t *testing.T, err error) { 18 | // t.Helper() 19 | if err != nil { 20 | t.Fatal(err) // line 22 21 | } 22 | } 23 | 24 | // END,OMIT 25 | 26 | var tests = []testing.InternalTest{ 27 | {"TestSomething", TestSomething}, 28 | } 29 | 30 | var benchmarks = []testing.InternalBenchmark{} 31 | 32 | var examples = []testing.InternalExample{} 33 | 34 | var matchPat string 35 | var matchRe *regexp.Regexp 36 | 37 | func matchString(pat, str string) (result bool, err error) { 38 | if matchRe == nil || matchPat != pat { 39 | matchPat = pat 40 | matchRe, err = regexp.Compile(matchPat) 41 | if err != nil { 42 | return 43 | } 44 | } 45 | return matchRe.MatchString(str), nil 46 | } 47 | 48 | func main() { 49 | testing.Main(matchString, tests, benchmarks, examples) 50 | } 51 | -------------------------------------------------------------------------------- /examples/time-string.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | func main() { 9 | t := time.Now() 10 | fmt.Println(t.String()) 11 | } 12 | -------------------------------------------------------------------------------- /img/party-gopher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davecheney/go-1.9-release-party/2df824b8b3c3feec85cddd6109ada43787dcb448/img/party-gopher.png -------------------------------------------------------------------------------- /presentation.slide: -------------------------------------------------------------------------------- 1 | Go 1.9 Release Party 2 | Your Meetup 3 | 25 Aug 2017 4 | 5 | Gopher 6 | @golang 7 | https://golang.org 8 | 9 | * License and Materials 10 | 11 | This presentation is licensed under the [[https://creativecommons.org/licenses/by-sa/4.0/][Creative Commons Attribution-ShareAlike 4.0 International]] licence. 12 | 13 | The materials for this presentation are available on GitHub: 14 | 15 | .link https://github.com/davecheney/go-1.9-release-party 16 | 17 | You are encouraged to remix, transform, or build upon the material, providing you distribute your contributions under the same license. 18 | 19 | If you have suggestions or corrections to this presentation, please raise [[https://github.com/davecheney/go-1.9-release-party/issues][an issue on the GitHub project]]. 20 | 21 | * Go 1.9 22 | 23 | Go 1.9 is released 🎉 24 | 25 | .link https://blog.golang.org/go1.9 Go 1.9 Announcement 26 | 27 | Go 1.9 is the 10th release in the Go 1 series. It follows from the previous version, Go 1.8, [[https://blog.golang.org/go1.8][released on the 16th of February, 2017]] 28 | 29 | .link http://golang.org/doc/go1.9 Go 1.9 Release Notes 30 | 31 | * What's happened in the last six months? 32 | 33 | What's changed? 34 | 35 | - Language changes 36 | - Ports 37 | - Performance 38 | - Toolchain changes 39 | - Changes to the standard library 40 | 41 | * Language changes 42 | 43 | * Type Aliases 44 | 45 | Go now supports type aliases to support gradual code repair while moving a type between packages. 46 | 47 | In short, a type alias declaration has the form: 48 | 49 | type T1 = T2 50 | 51 | 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. 52 | 53 | The type alias design document and an article on re-factoring cover the problem in detail. 54 | 55 | .link https://golang.org/design/18130-type-alias Type aliases design document. 56 | .link https://talks.golang.org/2016/refactor.article Code base Re-factoring (with help from Go). 57 | 58 | #* Type Aliases (example) 59 | # 60 | # 61 | #.play -edit examples/type-aliases.go 62 | 63 | * Ports 64 | 65 | No new ports were added during 1.9, however there have been some changes to the support platforms. 66 | 67 | - ppc64 Big and Little Endian require Power8 hardware. Unless you're running Go on a PowerMac G5, this doesn't affect you. 68 | - Go 1.9 is the last release to support FreeBSD 9.3. Go 1.10 will require FreeBSD 10.3 or later. 69 | - Go 1.9 requires OpenBSD 6.0 or later. OpenBSD 5.9 is no longer supported (but it's not supported by the OpenBSD project either, ᕕ( ᐛ )ᕗ). 70 | 71 | * Performance 72 | 73 | * Performance 74 | 75 | As always, the changes are so general and varied that precise statements about performance are difficult to make. 76 | 77 | Most programs should run a bit faster, due to speedups in the garbage collector and optimizations in the standard library. 78 | 79 | Do you have a Go 1.9 performance story to tell? Blog it, and I'll retweet the crap out of it. 80 | 81 | * Garbage collector specific 82 | 83 | - 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. 84 | - 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. 85 | - Large object allocation performance is significantly improved in applications using large (>50GB) heaps containing many large objects. 86 | - In Go 1.8 the cost of calling `runtime.MemStats` is proportional to the size of the heap; Austin recently timed it at ~1.7ms per Gb. In Go 1.9 the function now takes less than 100µs even for very large heaps. 87 | 88 | .link https://golang.org/issue/13613 89 | 90 | * Toolchain improvements 91 | 92 | * Parallel Compilation 93 | 94 | The `go` tool has always compiled `runtime.NumCPUs()` packages in parallel. 95 | 96 | With Go 1.9, inside a single package functions are now compiled in parallel. 97 | 98 | Depending on the width and height of your dependency tree, and the number of cores available, this could give no speed up, or a measurable improvement. 99 | 100 | export GO19CONCURRENTCOMPILATION=0 101 | 102 | disables this behaviour. 103 | 104 | * ./... no longer matches vendor/... 105 | 106 | No more 107 | 108 | go test $(go list ./... | grep -v vendor) 109 | 110 | shenanigans. 111 | 112 | If you _do_ want to test your code under `vendor/`, you can use something like 113 | 114 | go test ./vendor/... 115 | 116 | .link https://github.com/golang/go/issues/19090 117 | .link https://golang.org/doc/go1.9#vendor-dotdotdot 118 | 119 | * Default $GOROOT 120 | 121 | The go tool will now use the path from which it was invoked to attempt to locate the root of the Go install tree. 122 | 123 | This means that if the entire Go installation is moved to a new location, the go tool should continue to work as usual. 124 | 125 | This is one less reason to need to explicitly set `$GOROOT`. 126 | 127 | _Note:_ this does not affect the result of the `runtime.GOROOT` function, which will continue to report the original installation location; this may be fixed in later releases. 128 | 129 | * go env -json 130 | 131 | The new `go`env`-json` flag enables JSON output, instead of the default OS-specific output format. 132 | 133 | % go env -json 134 | { 135 | "CC": "gcc", 136 | "CGO_CFLAGS": "-g -O2", 137 | "CGO_CPPFLAGS": "", 138 | "CGO_CXXFLAGS": "-g -O2", 139 | "CGO_ENABLED": "1", 140 | "CGO_FFLAGS": "-g -O2", 141 | "CGO_LDFLAGS": "-g -O2", 142 | "CXX": "g++", 143 | "GCCGO": "gccgo", 144 | "GOARCH": "amd64", 145 | "GOGCCFLAGS": "-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build254210362=/tmp/go-build -gno-record-gcc-switches", 146 | "GOHOSTARCH": "amd64", 147 | "GOHOSTOS": "linux", 148 | "GOOS": "linux", 149 | "GOPATH": "/home/dfc", 150 | "GOROOT": "/home/dfc/go", 151 | "GOTOOLDIR": "/home/dfc/go/pkg/tool/linux_amd64" 152 | } 153 | 154 | * go test -list 155 | 156 | 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. 157 | 158 | % go test -list Compare bytes 159 | TestCompare 160 | TestCompareIdenticalSlice 161 | TestCompareBytes 162 | BenchmarkBytesCompare 163 | BenchmarkCompareBytesEqual 164 | BenchmarkCompareBytesToNil 165 | BenchmarkCompareBytesEmpty 166 | BenchmarkCompareBytesIdentical 167 | BenchmarkCompareBytesSameLength 168 | BenchmarkCompareBytesDifferentLength 169 | BenchmarkCompareBytesBigUnaligned 170 | BenchmarkCompareBytesBig 171 | BenchmarkCompareBytesBigIdentical 172 | 173 | * go tool pprof 174 | 175 | pprof has received some love. 176 | 177 | Profiles produced by the runtime/pprof package now include symbol information, so they can be viewed in go tool pprof without the binary that produced the profile. 178 | 179 | % go test -test.run=xxx -test.bench=Max strings -test.cpuprofile=c.p 180 | BenchmarkSingleMaxSkipping-4 2000000 912 ns/op 10964.09 MB/s 181 | PASS 182 | ok strings 3.054s 183 | % go tool pprof c.p 184 | 185 | The `go`tool`pprof` command now uses the HTTP proxy information defined in the environment, using `http.ProxyFromEnvironment`. 186 | 187 | .link https://rakyll.org/profiler-labels/ Profiler labels in Go 188 | 189 | * Other toolchain improvements 190 | 191 | - Complex division is now C99-compatible. This has always been the case in gccgo and is now fixed in the gc toolchain. 192 | - The linker will now generate DWARF information for cgo executables on Windows. 193 | - The compiler now includes lexical scopes in the generated DWARF if the `-N`-l` flags are provided, allowing debuggers to hide variables that are not in scope. The `.debug_info` section is now DWARF version 4. 194 | - The values of `GOARM` and `GO386` now affect a compiled package's build ID, as used by the go tool's dependency caching. 195 | 196 | * Runtime changes 197 | 198 | * Mid-stack inlining 199 | 200 | Inlining has historically been limited to leaf functions because of the concern of aggressive inlining on stack trace output. 201 | 202 | Users of `runtime.Callers` should avoid directly inspecting the resulting PC slice and instead use `runtime.CallersFrames` to get a complete view of the call stack, or `runtime.Caller` to get information about a single caller. This is because an individual element of the PC slice cannot account for inlined frames or other nuances of the call stack. 203 | 204 | Specifically, code that directly iterates over the PC slice and uses functions such as `runtime.FuncForPC` to resolve each PC individually will miss inlined frames. To get a complete view of the stack, such code should instead use `CallersFrames`. 205 | 206 | Code that queries a single caller at a specific depth should use `Caller` rather than passing a slice of length 1 to `Callers`. 207 | 208 | `runtime.CallersFrames` has been available since Go 1.7, so code can be updated prior to upgrading to Go 1.9. 209 | 210 | .link https://github.com/golang/go/issues/17566 Issue 17566 211 | 212 | * runtime poller improvements 213 | 214 | Go has used epoll/kqueue/poll/select for _network_sockets_ for years. 215 | 216 | Reads/Writes to other file descriptors have traditionally consumed a thread during operation. 217 | 218 | Ian Lance Taylor landed a refactor that broke out the `runtime` polling subsystem and extended to work for the rest of the `os` package. 219 | 220 | The `os` package now uses the internal runtime poller for file I/O. This reduces the number of threads required for read/write operations on pipes, and it eliminates races when one goroutine closes a file while another is using the file for I/O. 221 | 222 | * Plugins 223 | 224 | Not much has changed, still lots to do. 225 | 226 | David Crawshaw gave a great talk about all the ways that Go code can be built to interact with other languages, and itself (plugins) at GopherCon this year. 227 | 228 | .link https://www.youtube.com/watch?v=x-LhC-J2Vbk David Crawshaw - Go Build Modes (GopherCon 2017) 229 | 230 | # * Tool changes 231 | 232 | # * go tool trace 233 | 234 | * Go one-line installer 235 | 236 | Jess Frazelle and Chris Broadfoot have been working on a one line binary installer for Go. 237 | 238 | .link https://groups.google.com/forum/#!searchin/golang-dev/getgo%7Csort:relevance/golang-dev/QrchAUETfUI/pOOZFx-GAgAJ Go one-line installer 239 | 240 | The installer is designed to both install Go as well as do the initial configuration of setting up the right environment variables and paths. 241 | 242 | Personally, I'm a little disapointed they didn't name it _upgoer_. 243 | 244 | * Changes to the standard library 245 | 246 | * Transparent Monotonic Time support 247 | 248 | 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. 249 | 250 | If a `Time` value has a monotonic clock reading, its string representation (as returned by `String`) now includes a final field "m=±value", where value is the monotonic clock reading formatted as a decimal number of seconds. 251 | 252 | The new methods Duration.Round and Duration.Truncate handle rounding and truncating durations to multiples of a given duration. 253 | 254 | .link https://golang.org/pkg/time/#hdr-Monotonic_Clocks 255 | .link https://golang.org/design/12914-monotonic 256 | 257 | * time.String (cont.) 258 | 259 | .play -edit examples/time-string.go 260 | 261 | Just as you shouldn't compare `t1`==`t2` because they may be in a different timezone, you shouldn't also compare `t1.String()`==`t2.String()`. 262 | 263 | - To compare times, use `time.Equal()` 264 | - When serialising `time.Time` values `time.MarshalBinary`, `time.MarshalJSON`, and `time.MarshalText` elide the monotonic component. 265 | 266 | .link https://www.youtube.com/watch?v=OuT8YYAOOVI Joe Tsai, Forward Compatible Go Code (GopherCon 2017) 267 | 268 | * sync.Map 269 | 270 | The `sync` package has a new type, `sync.Map` 271 | 272 | `sync.Map` 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. 273 | 274 | `sync.Map` is _not_ a general purpose replacement for a `sync.Mutex`/`RWMutex` and the built in `map` type. 275 | 276 | .link https://github.com/golang/go/issues/18177 277 | .link https://www.youtube.com/watch?v=C1EtfDnsdDs Lightning Talk: Bryan C Mills - An overview of sync.Map (GopherCon 2017) 278 | .link https://github.com/gophercon/2017-talks/blob/master/lightningtalks/BryanCMills-AnOverviewOfSyncMap/An%20Overview%20of%20sync.Map.pdf Lightning Talk: Bryan C Mills - An overview of sync.Map (Slides) 279 | 280 | * math/bits 281 | 282 | As an experiment in addressing the needs of low level crypto and bit twiddling needs of package writers, Go 1.9 includes a new package, `math/bits`. 283 | 284 | `math/bits` contains functions to operate on values representing bit shifts, rotates, masks, and counts. 285 | 286 | Where implemented by SSA backends, the `math/bits` functions are replaced by a native sequence of instructions. When no specific instruction exists, or is not implemented, the compiler treats the `math/bits` package as normal Go code. 287 | 288 | .link https://golang.org/pkg/math/bits/ math/bits 289 | 290 | .play -edit examples/math-bits.go /START/,/END/ 291 | 292 | * testing.Helper() 293 | 294 | The new `(*T).Helper` and `(*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. 295 | 296 | Use it to exclude testing helpers from `t.Errorf()` and `t.Fatalf()` tracebacks. 297 | 298 | .play -edit examples/testing-helper.go /START/,/END/ 299 | 300 | * And much more ... 301 | 302 | - `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. 303 | - `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. 304 | - `os/exec` - The `os/exec` package now de-duplicates environment variables in the `exec.Cmd.Env` slice. 305 | - `os/user` - `Lookup` and `LookupId` now work on Unix systems when `CGO_ENABLED=0` by reading the `/etc/passwd` file. 306 | - `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. 307 | 308 | .link https://golang.org/doc/go1.9#minor_library_changes 309 | 310 | * dep 311 | 312 | The official experiment. 313 | 314 | .link https://github.com/golang/dep 315 | 316 | Try it, use it, start making releases, start tagging your releases. 317 | 318 | .link https://www.youtube.com/watch?v=5LtMb090AZI Sam Boyer, GopherCon 2017 319 | .link https://dave.cheney.net/2016/06/24/gophers-please-tag-your-releases 320 | 321 | * Go 1.next 322 | 323 | The next release of Go will be ... wait for it ... Go 1.10. 324 | 325 | * Go.future 326 | 327 | A GopherCon in July Russ Cox 328 | 329 | .link https://blog.golang.org/toward-go2 Towards Go 2 (blog.golang.org) 330 | .link https://www.youtube.com/watch?v=0Zbh_vmAKvk Russ Cox, The Future of Go (GopherCon 2017) 331 | 332 | "The conversation for Go 2 starts today, and it's one that will happen in the open, in public forums like the mailing list and the issue tracker. Please help us at every step along the way. 333 | 334 | "Today, what we need most is experience reports. Please tell us how Go is working for you, and more importantly not working for you. Write a blog post, include real examples, concrete detail, and real experience. And link it on our wiki page. That's how we'll start talking about what we, the Go community, might want to change about Go. 335 | .caption Russ Cox 336 | 337 | .link https://github.com/golang/go/wiki/ExperienceReports Experience Reports (Go wiki) 338 | 339 | # experience reports 340 | # random proposals don't count, you have to explain what the problem is _before_ you start talking about what you want to change. 341 | 342 | * Conclusion 343 | 344 | .image img/party-gopher.png 345 | .caption image credit Renee French 346 | 347 | Upgrade to Go 1.9, now! 348 | 349 | I know I said this last time, but it's still true that Go 1.9 is literally the best version of Go so far. 350 | 351 | --------------------------------------------------------------------------------