What's new in Go 1.11?

18 October 2018

Dmitri Shuralyov

Go team, Google

A little about my username

It used to be shurcooL.

2

A little about my username

Now it's dmitshur.

3

Go 1.11

4

Go 1.11.1

Source: twitter.com/bradfitz/status/1047188695919472640

5

Go release cycle

Source: golang.org/s/release

6

Go 1.11

7

Go 1.11

8

Go 1.11

9

Go 1.11

Sources:

10

Ports

Dropped:

Minor additions, like -race on linux/ppc64le and -msan on linux/arm64.

riscv and riscv64 reserved as GOARCH values reserved for the future.

11

Tooling (besides modules)

12

Tooling - cmd/go

Have you ever tried to "run" a package?

$ go get -u import/path
$ go build import/path
$ go install import/path

$ go build
$ go install

$ go run import/path
go run: no go files listed
$ go run
go run: no go files listed
13

Tooling - cmd/go

Have you ever tried to "run" a package?

$ go run *.go
go run: cannot run *_test.go files (main_test.go)

*.go also ignores build tags.

14

Tooling - cmd/go

Have you ever tried to "run" a package?

$ go build -o /tmp/a && /tmp/a
...

go build was slower than go install before build/test cache of Go 1.10.

15

Tooling - cmd/go

Have you ever tried to "run" a package?

$ GOBIN=/tmp/bin go install && /tmp/bin/foo
...
16

Tooling - cmd/go

Have you ever tried to "run" a package?

$ gorun() { GOBIN=/tmp/gorun go install -v $* && $(GOBIN=/tmp/gorun go list -f '{{.Target}}' $*); }
$ gorun
...
17

Tooling - cmd/go

No more! Enter Go 1.11.

Source: golang.org/cmd/go/#hdr-Compile_and_run_Go_program

18

Tooling - cmd/go

Now you can just do:

$ go run import/path
$ go run .

$ go run import/path -foo -bar
$ go run . -foo -bar
19

Tooling - cmd/go

Source: golang.org/issue/22726

20

Tooling #2 - x/tools/go/packages

A replacement for go/build and x/tools/go/loader with several advantages:

21

Tooling #3 - gofmt

var _ = T{
    F1: 1,
    F2: 1,
    VeryLongNameJustBecause: 1,
    F3: 1,
}

The tweaked heuristic now gives us:

var _ = T{
    F1:                      1,
    F2:                      1,
    VeryLongNameJustBecause: 1,
    F3:                      1,
}
22

Tooling #4 - godoc versions for std

23

Tooling #5 - debugging

Optimized binaries now include more accurate info, like:

DWARF sections (debugging info) are now compressed by default

24

Runtime

25

Compiler #1 - indexed export format

Juju/c=4/l=4        46.3s ± 4%        38.0s ± 4%  -18.06%  (p=0.001 n=7+7)
Kubelet/c=4/l=4     48.1s ± 2%        39.0s ± 5%  -18.93%  (p=0.002 n=6+6)
26

Compiler #2 - unused type switch variables

func f(v interface{}) {
    switch x := v.(type) {
    }
}
27

Compiler #3 - inlining function calls

28

Compiler #4 - map clearing idiom

for k := range m {
    delete(m, k)
}
GoMapClear/Reflexive/1         92.2ns ± 1%  47.1ns ± 2%  -48.89%  (p=0.000 n=9+9)
GoMapClear/Reflexive/10         108ns ± 1%    48ns ± 2%  -55.68%  (p=0.000 n=10+10)
GoMapClear/Reflexive/100        303ns ± 2%   110ns ± 3%  -63.56%  (p=0.000 n=10+10)
GoMapClear/Reflexive/1000      3.58µs ± 3%  1.23µs ± 2%  -65.49%  (p=0.000 n=9+10)
GoMapClear/Reflexive/10000     28.2µs ± 3%  10.3µs ± 2%  -63.55%  (p=0.000 n=9+10)
29

Compiler #5 - slice extension

append(s, make([]T, n)...)
ExtendSlice/IntSlice         103ns ± 4%      57ns ± 4%   -44.55%  (p=0.000 n=18+18)
ExtendSlice/PointerSlice     155ns ± 3%      77ns ± 3%   -49.93%  (p=0.000 n=20+20)
ExtendSlice/NoGrow          50.2ns ± 3%     5.2ns ± 2%   -89.67%  (p=0.000 n=18+18)
30

Compiler #6 - prove pass

The prove pass derives facts from code, to be used to delete unnecessary
branches and bounds checks.

Most importantly, it now recognizes transitive relations:

The bounds check is what panics if the index is out of bounds, so in this case
it can be removed.

31

Standard library highlights #1

Let's begin with some of the most visible changes:

32

Standard library highlights #2

{{ $v := "init" }}
{{ if true }}
    {{ $v = "changed" }}
{{ end }}
v: {{ $v }} {{/* "changed" */}}<Paste>
ioutil.TempFile("", "foo-") // /tmp/foo-123456
ioutil.TempFile("", "foo-*.txt") // /tmp/foo-123456.txt
33

Standard library highlights #3

What about performance?

34

Side note on arm64 performance

Source: twitter.com/somospostpc/status/1041018921279741952

35

Special thanks

See also:

36

Thank you

Use the left and right arrow keys or click the left and right edges of the page to navigate between slides.
(Press 'H' or navigate to hide this message.)