What else is in Go 1.11?

原文作者:Daniel Martí https://mvdan.cc

Go 1.11

WebAssembly and Modules have already been covered.

Now onto the changes that won't make headlines!

Sources:

tip.golang.org/doc/go1.11

github.com/golang/go/issues?q=is:open+is:issue+milestone:Go1.11

Ports

Dropped:

Windows XP and Vista (300+ lines removed)

OSX 10.9 and earlier (120+ lines removed)

OpenBSD 6.1 and earlier

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

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

Tooling (besides modules)

Last release to supportGOCACHE=off

go testnow runsgo vetby default

go vetnow requires its input packages to typecheck

Last release wheregodochas a command-line interface

Tooling #2 - x/tools/go/packages

A replacement forwith several advantages:

Support for Modules - critical for third party tools

Support for patterns, like

Calls out togo listto find packages

Support for build systems like Bazel

Support loading dependencies via

Tooling #3 - gofmt

The tweaked heuristic now gives us:

Tooling #4 - godoc versions for std

Tooling #5 - debugging

Experimental support for calling Go functions in a debugger

Optimized binaries now include more accurate info, like:

Variable locations

Line numbers

Breakpoint locations

DWARF sections (debugging info) are now compressed by default

Runtime

Now uses a sparse heap, so the 512GiB limit is gone

Kernel calls on macOS and iOS now go through

This improves Go's compatibility with future macOS and iOS versions

Compiler #1 - indexed export format

The old format was sequential - entire packages had to be loaded

The new format is indexed, so the compiler only loads what it needs

Especially important for large projects and packages

--

Compiler #2 - unused type switch variables

gccgo and go/types already errored here

The compiler now does too, for consistency

Compiler #3 - inlining function calls

Funcs that callcan now be inlined

makes the inlining more agressive, also enabling mid-stack inlining

has been tweaked and improved

However,still makes some programs larger and slower

The heuristic needs more work for mid-stack inlining to be the default

Compiler #4 - map clearing idiom

Reuses the allocated memory for the map

Now skips the expensive range when possible

Compiler #5 - slice extension

Simpler than manually allocating a new slice and copying

Avoids an allocation if there's enough capacity

If a new backing array is needed, avoids clearing memory

twice

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:

Insideif n

Afters := make([]int, 20), it can provelen(s) == 20

Globally,10

s := make([]int, 20); if n

The bounds check is what panics if the index is out of bounds, so in this case

it can be removed.

Standard library highlights #1

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

Added os.UserCacheDir; $HOME/.cache on most Unix systems

os/user adds a osusergo build tag use pure Go without CGO_ENABLED=0

time now accepts parsing numeric timezones like +03

net/http adds support for CIDR and ports in NO_PROXY, like NO_PROXY=10.0.0.0/8

net/http/httputil.ReverseProxy gained an ErrorHandler

Some crypto funcs now randomly read an extra byte

Standard library highlights #2

can now modify variables via thetoken:

io/ioutil.TempFile can now be told where to put the random characters:

Standard library highlights #3

What about performance?

Some packages were optimized for arm64; especially crypto and byte handling

Pieces of math/big were rewritten to be much faster

Copying data between TCP connections is faster on Linux via the splice syscall

The mutex profile now includes reader/writer contention for sync.RWMutex

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20180817B1Z23M00?refer=cp_1026
  • 腾讯「云+社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。

扫码关注云+社区

领取腾讯云代金券