What's new in Go 1.11?
18 October 2018
Dmitri Shuralyov
Go team, Google
Dmitri Shuralyov
Go team, Google
It used to be shurcooL.
Now it's dmitshur.
Source: twitter.com/bradfitz/status/1047188695919472640
5
Source: golang.org/s/release
6
Sources:
github.com/golang/go/issues?q=is:closed+is:issue+milestone:Go1.11
dev.golang.org/release#Go1.11.2
10Dropped:
Minor additions, like -race on linux/ppc64le and -msan on linux/arm64.
riscv and riscv64 reserved as GOARCH values reserved for the future.
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
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.
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.
Have you ever tried to "run" a package?
$ GOBIN=/tmp/bin go install && /tmp/bin/foo ...
Have you ever tried to "run" a package?
$ gorun() { GOBIN=/tmp/gorun go install -v $* && $(GOBIN=/tmp/gorun go list -f '{{.Target}}' $*); }
$ gorun
...No more! Enter Go 1.11.
Source: golang.org/cmd/go/#hdr-Compile_and_run_Go_program
18Now you can just do:
$ go run import/path $ go run . $ go run import/path -foo -bar $ go run . -foo -bar
Source: golang.org/issue/22726
20
A replacement for go/build and x/tools/go/loader with several advantages:
./...GOCACHEvar _ = 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,
}
Optimized binaries now include more accurate info, like:
DWARF sections (debugging info) are now compressed by default
24libSystem.soJuju/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)
gccgo and go/types already errored herefunc f(v interface{}) {
switch x := v.(type) {
}
}panic can now be inlined-l=4 makes the inlining more agressive, also enabling mid-stack inlining-l=4 has been tweaked and improved-l=4 still makes some programs larger and slowerfor 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)
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)
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.
Let's begin with some of the most visible changes:
os.UserCacheDir; $HOME/.cache on most Unix systemsos/user adds a osusergo build tag use pure Go without CGO_ENABLED=0time now accepts parsing numeric timezones like +03net/http adds support for CIDR and ports in NO_PROXY, like NO_PROXY=10.0.0.0/8net/http/httputil.ReverseProxy gained an ErrorHandlercrypto funcs now randomly read an extra bytetext/template can now modify variables via the = token:{{ $v := "init" }}
{{ if true }}
{{ $v = "changed" }}
{{ end }}
v: {{ $v }} {{/* "changed" */}}<Paste>io/ioutil.TempFile can now be told where to put the random characters:ioutil.TempFile("", "foo-") // /tmp/foo-123456
ioutil.TempFile("", "foo-*.txt") // /tmp/foo-123456.txtWhat about performance?
arm64; especially crypto and byte handlingmath/big were rewritten to be much fastersplice syscallsync.RWMutex
Source: twitter.com/somospostpc/status/1041018921279741952
35See also: