即將發佈的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


分享到:


相關文章: