即将发布的Go 1.15中 ,哪些变化是你关注的?

更多Go资讯,欢迎微信公众号“Go语言中文网”关注我们,可领全套Go资料,每天学习 Go 语言

这是来自 4月 26 日 Go Remote Fest 会议地分享整理,原标题:《What’s coming in Go 1.15》,一起看看计划在今年 8 月份发布的 Go1.15 都有哪些值得关注的变化。本文提到的点,大部分已经 Merge,毕竟包括 8 月份只剩下 3 个月了。之前提到过,受疫情影响,这次的发布内容不会太多。

1、新的链接器

官方的设计文档地址:https://golang.org/s/better-linker,从命名看,是一个更好的链接器(这是废话),目前该链接器还未完成。

2、略微小了些的二进制文件

虽然很多人对 Go 二进制文件为什么“那么大”存在疑问,但不是软盘年代,这点空间真不需要在意。不过 Go 团队还是做了一些努力。

<code>package main
import (
  "io"
  "net/http"
  "os"
)
func main() {
  resp, _ := http.Get("https://golang.org/dl/")
  io.Copy(os.Stdout, resp.Body)
}
/<code>

看看结果对比:

<code>$ go version
go version go1.14.2 linux/amd64
$ gotip version

go version devel +49f10f3797 Sat Apr 25 02:19:12 2020 +0000 linux/amd64
$ go build -ldflags='-w -s' -o 114 
$ gotip build -ldflags='-w -s' -o 115
$ du -b 114 115
5111808 114
5009408 115
/<code>

2% 左右,虽然不多,但还在考虑进一步减小。

3、内嵌 tzdata(时区数据)

增加了一个新包:time/tzdata,当系统找不到时区数据时(比如 Windows 等),通过导入这个包,在程序中内嵌时区数据,也可以通过编译时传递 -tags timetzdata 来实现同样的效果。

具体查看这个 issue:https://github.com/golang/go/issues/38017 以及包 time/tzdata 的说明:https://tip.golang.org/pkg/time/tzdata/。

##4、增加 testing.TB.TempDir

测试生成临时文件挺常见的,这个为了更好的解决此问题。详情见 issue:https://github.com/golang/go/issues/35998。

5、增加 testing.T.Deadline

将 context 引入 testing 包。详情见 issue:https://github.com/golang/go/issues/28135。

6、关于 Ports 部分

darwin/386、darwin/arm 不再支持;riscv64 变得更好;linux/arm64 现在作为第一类 port 支持。

7、API 的变动

1)net/url.URL RawFragment 和 EscapedFragment ,详情见 issue:https://github.com/golang/go/issues/37776;

2)net/url.URL.Redacted,详情见 issue:https://github.com/golang/go/issues/34855;

3)time.Ticker.Reset,我们知道 Timer 是有 Reset 的,这次为 Ticker 也增加,详情见 issue:https://github.com/golang/go/issues/33184;

4)regexp.Regexp.SubexpIndex,详情见 issue:https://github.com/golang/go/issues/32420;

5)sync.Map.LoadAndDelete,详情见 issue:https://github.com/golang/go/issues/33762;

6)crypto/tls.Dialer.DialContext,详情见 issue:https://github.com/golang/go/issues/18482;

还有其他一些 API 变动,不一一列举。

8、工具链

1)增加 go env GOMODCACHE:https://github.com/golang/go/issues/34527;

2)opt-in fallbacks in GOPROXY:https://github.com/golang/go/issues/37367;

3)vet:warn about string(int) 和 detect impossible interface assertions:https://github.com/golang/go/issues/32479 和 https://github.com/golang/go/issues/4483;

4)println 允许打印两个值。println(twoValues());

5)panic:显示可打印的值而不是地址。比如:

<code>type MyString string
panic(MyString("hello"))
/<code>

现在打印:

<code>panic: (main.MyString) (0x48aa00,0x4c0840)
/<code>

期望打印:

<code>panic: main.MyString("hello")
/<code>

可读性会好很多。

9、性能

1)在 amd64 上更好的写屏蔽;

2)在 Linux 上,forkAndExec 使用 dup3;

3)sha512 算法速度提升 15%;

4)ReadMemStats 延迟降低 95%;

5)关闭状态的 channel 接收速度提升 99%;

6)将小的 int 值转为 interface{} 不额外分配内存;

10、如何试用?

可以通过执行如下命令提前使用 Go1.15:

<code>go get golang.org/dl/gotip
/<code>

11、更多的改动,参看 PPT

https://docs.google.com/presentation/d/1veyF0y6Ynr6AFzd9gXi4foaURlgbMxM-tmB4StDrdAM/edit#slide=id.g840eaeb4b4_0_8 ,另外这里有会议的完整视频:

GoRemoteFest 2020 会议视频全集 - https://www.youtube.com/watch?v=OZSJ2fwSSUM&list=PLdeYrDm3hJTh21xi3rezgsSqrZl_Xs0VA


分享到:


相關文章: